Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete local IP based printers with a VB Script

Status
Not open for further replies.

shabbarankers

Technical User
Jan 7, 2011
19
GB
Hi All,

I'm trying desperately to delete a local IP based printer from some workstations. I don't want to delete ALL local IP printers just one that's been replaced. When I call up

WshShell.Run ("rundll32 printui.dll,PrintUIEntry /q /dl /n " & chr(34) & "Printer Name Here" & chr(34))

It doesn't remove the printer just carries on with the script and adds another of the same name. Can anyone help me with this please?

Thanks
 
Hi Geates,

Thanks for looking at this

Code:
'Printer Install

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Set WshShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:") 

Dim allPrinters(99, 2)
Dim foundFlag
Dim searchName
Dim i, count


	WshShell.Run ("rundll32 printui.dll,PrintUIEntry /dl /n " & chr(34) & "A4 Printer" & chr(34))	

On Error resume Next

'If printer not found then install
If foundFlag = false then
	Set objNewPort = objWMIService.Get _ 
	("Win32_TCPIPPrinterPort").SpawnInstance_ 
		objNewPort.Name = "IP_192.168.0.103" 
		objNewPort.Protocol = 1 
		objNewPort.HostAddress = "192.168.0.103" 
		objNewPort.PortNumber = "9100" 
		objNewPort.SNMPEnabled = False 
		objNewPort.Put_

			WshShell.run ("rundll32.exe printui.dll,PrintUIEntry /if /b "&chr(34)&"A4 Printer"&chr(34)&" /f "&chr(34)&"\\fileshare\Printers\Brother-1450 x64\BHPCL5E.INF"&chr(34)&" /r "&chr(34)&"IP_192.168.0.103"&chr(34)&" /m "&chr(34)&"Brother PCL5e Driver"&chr(34)&" /z")

End If	

'If printer not found then install
If foundFlag = false then
	Set objNewPort = objWMIService.Get _ 
	("Win32_TCPIPPrinterPort").SpawnInstance_ 
		objNewPort.Name = "IP_192.168.0.102" 
		objNewPort.Protocol = 1 
		objNewPort.HostAddress = "192.168.0.102" 
		objNewPort.PortNumber = "9100" 
		objNewPort.SNMPEnabled = False 
		objNewPort.Put_

		WshShell.run ("rundll32.exe printui.dll,PrintUIEntry /if /b "&chr(34)&"A3 Printer"&chr(34)&" /f "&chr(34)&"\\fileshare\Printers\ss0emenu.inf"&chr(34)&" /r "&chr(34)&"IP_192.168.0.102"&chr(34)&" /m "&chr(34)&"MX-2640N PCL6"&chr(34)&" /z")

End If	

'End of Script
Wscript.Quit
 
Hi

Its defined underneath Dim allPrinters(99, 2) ->> Dim foundFlag
 
It's dimensioned (memory has been allocated to store the value) but it hasn't been defined (it has no value). Variables that aren't defined have a default value of 0 (false). The "'If printer not found then install" IF/THEN evaluates to true and the printer is installed, hence the duplicate. I think you want...

Code:
[b]foundFlag =[/b] WshShell.Run ("rundll32 printui.dll,PrintUIEntry /dl /n " & chr(34) & "A4 Printer" & chr(34))

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top