Solved

vbscript delete printers

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

OfficeMate Freezes on login or does not load after login credentials are input.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
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…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

735 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