Priscilla_Hora
asked on
Remove printer via script
I have migrated my printers from one server (A) to another (B)
I want to remove all printers from client PCs which are attached to the old print server.
For example: \\A\printer1
How can I achieve this by using kix logon script?
Keep in mind that I only want to remove printers attached to server A, I want to leave all local printers.
Thanks
I want to remove all printers from client PCs which are attached to the old print server.
For example: \\A\printer1
How can I achieve this by using kix logon script?
Keep in mind that I only want to remove printers attached to server A, I want to leave all local printers.
Thanks
Oh, forgot the VBS code, here it is:
'====================
strComputer = "."
strOldServer = "\\OLDPRNSVR"
Set objNetwork = CreateObject("WScript.Netw ork")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = False")
If colPrinters.Count <> 0 Then
For Each objPrinter In colPrinters
If UCase(objPrinter.ServerNam e) = UCase(strOldServer) Then objNetwork.RemovePrinterCo nnection objPrinter.DeviceID, True, True
Next
End If
'===============
Regards.
Rob.
'====================
strComputer = "."
strOldServer = "\\OLDPRNSVR"
Set objNetwork = CreateObject("WScript.Netw
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = False")
If colPrinters.Count <> 0 Then
For Each objPrinter In colPrinters
If UCase(objPrinter.ServerNam
Next
End If
'===============
Regards.
Rob.
ASKER
That works.
How can I do the following instead:
If user is connected to \\oldserver\oldprinter then add \\newserver\newprinter and delete \\oldserver\oldprinter
with possibility of setting it to default if old printer was default.
Is that possible rather than removing the printer. Can the script see that printer 1 is connect and just change the server from old to new?
How can I do the following instead:
If user is connected to \\oldserver\oldprinter then add \\newserver\newprinter and delete \\oldserver\oldprinter
with possibility of setting it to default if old printer was default.
Is that possible rather than removing the printer. Can the script see that printer 1 is connect and just change the server from old to new?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the grade. By the way, ahoffman's link to prnport.vbs can be used, in conjuction with my script, to also remove the TCP/IP port associated with a printer. You can strPort = objPrinter.PortName to determine the printer port, then use prnport.vbs to remove that port (after deleting the printer) with
Set objShell = CreateObject("Wscript.Shel l")
objShell.Run "cscript prnport.vbs -d -r " & strPort, 0, True
Regards,
Rob.
Set objShell = CreateObject("Wscript.Shel
objShell.Run "cscript prnport.vbs -d -r " & strPort, 0, True
Regards,
Rob.
Shell 'wscript.exe yourscript.vbs'
And you can also try to convert a VBS to KIX by using this:
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=139729&site_id=1#import
Regards,
Rob.