|
|
Question : Delete network printer(s) using vbs or WSH
|
|
I research MS KB, but no solution to my problem... here it goes. Little Background 1. I had a login.bat script that map users; profiles and everything else, it also call a c:\printer.bat in the local machine to get the printer connected to that specific machine (all W2K so \\servername\pr1) was ok, now I am moving away from .bat file to vbs or wsh login to W2k, my script maps users profiles drives and everything else by GPO, no problem there,
PROBLEM: I need to have a script that will erase any existing printers in the profile of the user as he/she login and then attach the printer that belong to that specific workstation (no local printers involve)
E.g. 1st floor \\server\pr1 2nd floor \\server\pr2 but when user moves from 1st floor to 2nd floor the pr1 needs to get erase and pr2 needs to be added (back and forth)
thank you
|
Answer : Delete network printer(s) using vbs or WSH
|
|
That might help you.
set o_net = CreateObject("WScript.Network") Set o_prt_dic = CreateObject("Scripting.Dictionary")
'------------------- Enable Error Handler
on error resume next
'------------------- Get User Printers
err.clear set usr_prt = o_net.EnumPrinterConnections if err.number = 0 then For i = 0 to usr_prt.Count - 1 Step 2 o_prt_dic.add usr_prt.Item(i+1), i Next end if
'------------------- Remove Old Printers
if o_prt_dic.exists("\\server\printer") then o_net.removeprinterconnection "\\server\printer", true, true end if
|
|
|
|
|