Solved

vbscript delete printers

Posted on 2014-01-02
4
485 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now