1cainr Posted March 2, 2011 Share Posted March 2, 2011 (edited) Hello,I created this script for my windows xp 64-bit users and we are now moving them onto windows 7 64 bit. However, when the script runs on logon, it skips the section which its suppose to run and thinks its a 32-bit machine. Seems to run this bit instead: Else ' A batch file is used on a 32-Bit OS Dim wshell set wshell = CreateObject("WScript.Shell") wshell.run "cbc_32Bitversion.bat" set wshell = nothingEnd ifCAN YOU SEE A PROBLEM WITH THE SCRIPT? SEE FULL CODE BELOW: Option ExplicitDim objNetwork,colDrives,i,strComputer, objWMIService, colOperatingSystems, objOperatingSystem, strCaption, colInstalledPrinters, objPrinter, wshShell, strUserName ' Use current machine strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem")For Each objOperatingSystem in colOperatingSystems strCaption = LCase(objOperatingSystem.Caption)If (InStr(strCaption, "x64") > 0) Then Set objNetwork = CreateObject("Wscript.Network") Set colDrives = objNetwork.EnumNetworkDrives ' Force Removal of network drives and remove from user profile For i = 0 to colDrives.Count-1 Step 2 objNetwork.RemoveNetworkDrive colDrives.Item(i),TRUE,TRUE Next ' Map network drives to user profile objNetwork.MapNetworkDrive "P:", "\\server\public", True objNetwork.MapNetworkDrive "V:", "\\server\J", True objNetwork.MapNetworkDrive "S:", "\\server\E", True objNetwork.MapNetworkDrive "G:", "\\server\ca", True objNetwork.MapNetworkDrive "R:", "\\server\data", True objNetwork.MapNetworkDrive "I:", "\\server\Inv", True ' Find local printers Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * From Win32_Printer Where Network = True") ' Force Removal of printers from user profile For Each objPrinter in colInstalledPrinters objPrinter.Delete_ Next ' Connect printers to user profile Dim multiPrinter Set multiPrinter = CreateObject("WScript.Network") multiPrinter.AddWindowsPrinterConnection "\\server\eng01-64" multiPrinter.AddWindowsPrinterConnection "\\server\inte01-64" multiPrinter.AddWindowsPrinterConnection "\\server\cad01-64" multiPrinter.AddWindowsPrinterConnection "\\server\cad02-64" multiPrinter.SetDefaultPrinter "\\server\cad02-64" 'Assign users different default printers and mapped drives Set wshShell = WScript.CreateObject( "WScript.Shell" ) strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) If strUserName = "mark" or strUserName = "john" Then objNetwork.MapNetworkDrive "T:", "\\server\5000", True End IfElse ' A batch file is used on a 32-Bit OS Dim wshell set wshell = CreateObject("WScript.Shell") wshell.run "cbc_32Bitversion.bat" set wshell = nothingEnd ifNextWScript.Quit Edited March 2, 2011 by gunsmokingman Added Code Tags Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 2, 2011 Share Posted March 2, 2011 The first problem you have is 1:\ strCaption = LCase(objOperatingSystem.Caption) strCaption = Microsoft Windows 7 Ultimate 2:\This will always return the 32 bit If (InStr(strCaption, "x64") > 0) Then Perhaps something like this would be better'-> Without Using strComputer = "."Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") '-> Using strComputer = "."'Dim strComputer : strComputer = "."'Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _'strComputer & "\root\cimv2") Dim Obj, X64 :X64 = False For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_Processor") If Obj.AddressWidth = 64 Then X64 = True Next If X64 = True Then WScript.Echo "Confirm X64" Else WScript.Echo "Confirm X32" End If I will post a better script later, but the above code should help out.Here is a updated scriptOption Explicit'-> Objects For Script Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Net :Set Net = CreateObject("Wscript.Network")'-> Without Using strComputer = "." Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") '-> Using strComputer = "."'Dim strComputer : strComputer = "."'Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _'strComputer & "\root\cimv2") '-> Varibles And CheckDim i, Obj, X64 :X64 = False For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_Processor") If Obj.AddressWidth = 64 Then X64 = True Next'-> Confirm x64 Or x32 OS If X64 = True Then ' WScript.Echo "Confirm X64" Drives() Printer() Else WScript.Echo "Confirm X32" End If Function Drives()' WScript.Echo "Code Here For Re Map Network Drives" For i = 0 to Net.EnumNetworkDrives.Count -1 Step 2 Net.RemoveNetworkDrive colDrives.Item(i),TRUE,TRUE Next'-> Map network drives to user profile Net.MapNetworkDrive "P:", "\\server\public", True Net.MapNetworkDrive "V:", "\\server\J", True Net.MapNetworkDrive "S:", "\\server\E", True Net.MapNetworkDrive "G:", "\\server\ca", True Net.MapNetworkDrive "R:", "\\server\data", True Net.MapNetworkDrive "I:", "\\server\Inv", True End Function Function Printer()' WScript.Echo "Code Here For Printers"'-> Remove Printers From User Profile For Each Obj In Wmi.ExecQuery("Select * From Win32_Printer Where Network = True") Obj.Delete_ Next Net.AddWindowsPrinterConnection "\\server\eng01-64" Net.AddWindowsPrinterConnection "\\server\inte01-64" Net.AddWindowsPrinterConnection "\\server\cad01-64" Net.AddWindowsPrinterConnection "\\server\cad02-64" Net.SetDefaultPrinter "\\server\cad02-64" '-> Assign Users Different Default Printers And Mapped Drives Dim User :User = Act.ExpandEnvironmentStrings("%UserName%") If InStr(1,User, "John",1) Or _ InStr(1,User, "Mark",1) Then Net.MapNetworkDrive "T:", "\\server\5000", True End If End Function Could you post the batch file code,because you can most likely have it coded to the script, instead of a separae Batch File. Link to comment Share on other sites More sharing options...
1cainr Posted March 3, 2011 Author Share Posted March 3, 2011 (edited) Please see batch file below, i use this on the users which use 32-bit and 64-bit machine. Ill try the vbs script above, thank you :-)ECHO OFFclsECHO Initialising user environment ...echo Running old scriptif exist G: net use G: /delete >nulnet use G: \\server\cam /persistent:noif exist P: net use P: /delete >nulnet use P: \\server\pub /persistent:noif exist S: net use s: /delete >nulnet use S: \\server\Share/persistent:noif exist R: net use R: /delete >nulnet use R: \\server\radan/persistent:nocon2prt /fcon2prt /c \\server\print1con2prt /c \\server\print2con2prt /c \\server\print3con2prt /cd \\server\print4 Edited March 3, 2011 by gunsmokingman Added Code Box Link to comment Share on other sites More sharing options...
1cainr Posted March 3, 2011 Author Share Posted March 3, 2011 (edited) Hello,I only used the batch file because i thought this VBS script wouldnt work on the 32-Bit operating systemWhen i run the script on a 64-Bit OS i get the following error:"Line 34 Char 7 Error Variable is undefined: 'colDrives'Code 800A01F4Source Microsoft VBScript runtime error "Thank you,Richard Edited March 3, 2011 by 1cainr Link to comment Share on other sites More sharing options...
1cainr Posted March 3, 2011 Author Share Posted March 3, 2011 (edited) Ive got the script working by putting two lines in:Option Explicit'-> Objects For Script Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Net :Set Net = CreateObject("Wscript.Network")'-> Without Using strComputer = "." Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")[color="#FF0000"]dim coldrives[/color]'-> Using strComputer = "."'Dim strComputer : strComputer = "."'Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _'strComputer & "\root\cimv2") '-> Varibles And CheckDim i, Obj, X64 :X64 = False For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_Processor") If Obj.AddressWidth = 64 Then X64 = True Next'-> Confirm x64 Or x32 OS If X64 = True Then ' WScript.Echo "Confirm X64" Drives() Printer() Else WScript.Echo "Confirm X32"Drives() Printer() End If Function Drives()Set colDrives = Net.EnumNetworkDrives() Those two lines make the script work :-) However when i run the script on a 32-bit OS it brings up the error: The parameter is incorrect for "Set colDrives = Net.EnumNetworkDrives()" Edited March 3, 2011 by gunsmokingman Added Code Box Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 3, 2011 Share Posted March 3, 2011 From what you posted this is what causing the problemChange This Area'-> Map network drives to user profileAdd this line to the code'-> Map network drives to user profileOn Error Resume Next Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now