Link to home
Start Free TrialLog in
Avatar of JeffBeall
JeffBeallFlag for United States of America

asked on

vbscript delete printers

I'm not a scripter so I googled around and found a script to remove all network printers, and it works great for the win7 computers I work on. I was hoping someone wouldn't mind giving a brief description of some of the things going on in the script I found, because I'm trying to learn how to script. So this is the script

 strComputer = "."
 
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
 Set colInstalledPrinters = objWMIService.ExecQuery _
 ("Select * from Win32_Printer Where Network = TRUE")
 
 For Each objPrinter in colInstalledPrinters
 if (objPrinter.network) then
 objPrinter.Delete_
 end if
 Next

from what I can tell, I think

strComputer = "."

Is a variable set to the local computer name, although, I don't get how it knows that the period is the local computer name.

"winmgmts:\\"   and  "\root\cimv2"

I have know idea what this is all about, I have picked up that the & between thing is kind of like and, so a command that looks like this

\\ & servername & \  & computername
is actually this
\\servername\computername

also, for

objPrinter.network    and    objPrinter.Delete

seems self explanitory, that objPrinter.network is network printers and objPrinter.Delete is to delete a printer - but I was wondering if there is a list of these commands somewhere with a brief description of what they do.

so if anyone has a minute or two, just for a quick explaination of what is happening with this script, I would really appreciate it.
ASKER CERTIFIED SOLUTION
Avatar of Seaton007
Seaton007
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JeffBeall

ASKER

thanks you for the explanation,

so do you mean that

cimv2 is a command that WMI uses?

I look on the link you provided and didn't see cimv2 as a command. Also, does that mean that WMI is needed to call a command?
wait - never mind,

I clicked on some of the links and saw that there is more to the link you provided, and that helped explain some things.

Thank you again for the help.
thank you.