Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vbscript delete printers

Posted on 2014-01-02
4
Medium Priority
?
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
Seaton007 earned 2000 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
Suggested Courses

704 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