Link to home
Start Free TrialLog in
Avatar of Brent387
Brent387Flag for United States of America

asked on

Remove Printer Installed as a Device VBScript

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

Avatar of Tony Massa
Tony Massa
Flag of United States of America image

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

Avatar of Brent387

ASKER

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.
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
ASKER CERTIFIED SOLUTION
Avatar of Tony Massa
Tony Massa
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial