Remove Printer Installed as a Device VBScript

Brent387
Brent387 used Ask the Experts™
on
Hello,

I have attached a script below which I don't think will work when deployed and I also don't think that it's the best method for doing this:

A colleague installed a printer in our remote office as a device and not a printer. We'd like to use a script to remove this device/printer but the standard remove printer script that I had isn't working on it. Our users run Windows 7 x64.

Can anyone offer any suggestions on the existing script or offer a better solution to do this?

Thank you
strComputer = "."
strQuery="Select * from Win32_PNPSignedDriver"

Set objWMIService=GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")

Set ColDevice=objWMIService.ExecQuery(strQuery) 
For Each objDevice in ColDevice
	strDev=objDevice.FriendlyName

If strDev=("XRX0000AAD33FF2") Then
	objDevice.StopService

End if
Next

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can use DevCon utility to add/remove devices remotely:
http://www.osronline.com/ddkx/ddtools/devcon_59f7.htm

If you get thehardware ID, you can remove it with this command:

devcon /r remove "PCI\VEN_8086&DEV_7110"
Untitled.gif
You would use a command remotely, like:

devcon -m:computername remove "PCI\VEN_8086&DEV_7110"

Just change the PCI\VEN_8086&DEV_7110 to the hardware ID of the printer

DEVCON DOWNLOAD:  http://support.microsoft.com/kb/311272
Here's another script to try  http://gallery.technet.microsoft.com/ScriptCenter/en-us/658b88e8-012c-4dff-8fc7-a658cb1c6317:


strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\roo\cimv2") 
Set colInstalledPrinters =  objWMIService.ExecQuery _ 
    ("Select * from Win32_Printer where DeviceID = 'Printer1'") 
For Each objPrinter in colInstalledPrinters 
    objPrinter.Delete_ 
Next

Open in new window

Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Author

Commented:
That script did not work. I think it needs to look for devices and not printers. Would I have to install the DevCon utility on all the remote computers?
No, you can run devcon against a remote computer...using my second post as a guide.

Author

Commented:
Devcon does not install. It says that each version is incompatible with my OS. I have Win7x64
Apparently, there is an updated version in this package:
http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=36a2630f-5d56-43b5-b996-7633f2ec14ff

I will extract it from the ISO and see if I can upload it here.

Or, you can just use devcon from any x86 computer.  I use it on my Win7x86 laptop.
Try this version of devcon
devcon.exe
Fyi for anyone interested, if you download the ISO, the devcon utility is in the WDM\setuptools_x64fre.msi package.

http://social.technet.microsoft.com/wiki/contents/articles/how-to-obtain-the-current-version-of-device-console-utility-devcon-exe.aspx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial