Solved

vbscript delete printers

Posted on 2014-01-02
4
488 Views
Last Modified: 2014-01-02
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.
0
Comment
Question by:JeffBeall
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
Seaton007 earned 500 total points
ID: 39751543
The period has been used to indicate localhost for a long time in Windows based systems.

wingmgmts and cimv2 are references to WMI which is used to carry out this procedure.

Yes, the "&" concatenates the items on either side of it.

Here is a list of the commands and what they do:
http://ss64.com/vb/
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 39751671
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?
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 39751675
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.
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 39751679
thank you.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question