Hi,
I create one .vbs file to migrate all printers to new print server for all my office user, deployment successful but the script doesn't run at all. If i run the script locally, it able to migrate all printer to new print server without any issue. Below is my script of the migration process and i already try using cscript.exe xxx.vbs as command line , and also using bat file to trigger the .vbs file also not able to run. Anyone have any idea?
Const ForAppending = 8
Const ForReading = 1
Dim WshNetwork, objPrinter, objOutputFile, intDrive, intNetLetter
Set WshNetwork = CreateObject ("Wscript.Network")
'provide access to window networking method to easily retrieve information like network share, printer, computer name
'username and domain
Set ObjWMIService = GetObject ("Winmgmts:{impersonationLevel=impersonate}!\\" & WshNetwork.ComputerName & "\root\cimv2")
'return information about computer registry
Set InstPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
'List the printer management properties
Set objFSO = CreateObject("Scripting.FileSystemObject")
'reading and writing text file
'Filesystemobject assign to an object and using Createfile method to create
'new file or using current file
Set WshShell = WScript.CreateObject("WScript.Shell")
'wshshell use to run a program locally, modify registry, create shortcut
'access system folder
fileOutput = "printer.txt"
'If objFSO.FileExists (fileOutput)Then
'objFSO.DeleteFile (fileOutput)
'End If
Set objOutputFile = objFSO.OpenTextFile (fileOutput, ForAppending, True)
For Each objPrinter in InstPrinters
If Left(objPrinter.Name, 11)= "\\myps2\MLP" Then
objOutputFile.WriteLine(objPrinter.Name)
'strTest = Left(objPrinter.Name, 2)
'objOutputFile.WriteLine(objPrinter.Name)
Wscript.Echo "This line is " & objPrinter.Name
strChar = Right(objPrinter.Name ,5)
WScript.Echo "This printer name is: " & strChar
WshNetwork.RemovePrinterConnection(objPrinter.Name)
WshNetwork.AddWindowsPrinterConnection ("\\myps\" & strChar)
Else
If Left(objPrinter.Name, 11)= "\\myps2\MDP" Then
objOutputFile.WriteLine(objPrinter.Name)
'strTest = Left(objPrinter.Name, 2)
'objOutputFile.WriteLine(objPrinter.Name)
Wscript.Echo "This line is " & objPrinter.Name
strChar = Right(objPrinter.Name ,5)
WScript.Echo "This printer name is: " & strChar
WshNetwork.RemovePrinterConnection(objPrinter.Name)
WshNetwork.AddWindowsPrinterConnection ("\\myps\" & strChar)
Else
If Left(objPrinter.Name, 12)= "\\myps2\MLAB" Then
objOutputFile.WriteLine(objPrinter.Name)
'strTest = Left(objPrinter.Name, 2)
'objOutputFile.WriteLine(objPrinter.Name)
Wscript.Echo "This line is " & objPrinter.Name
'strChar = Right(objPrinter.Name ,6)
WScript.Echo "This printer name is: " & strChar
WshNetwork.RemovePrinterConnection(objPrinter.Name)
'WshNetwork.AddWindowsPrinterConnection ("\\myps\" & strChar)
End If
End If
End If
Next