Jump to content

Recommended Posts

Posted

Hi All,

 

Having a nightmare with printers scripts. I have found a number of examples on here kindly given by members but I am struggling reformatting etc.

 

My goal is to remove all network printer connections, then query the first 4 letters of our computer names and add a printer dependant on the first 4 of the computer name and install the printer driver.

 

I need a super simple script to achieve this does anyone have one?

 

(printers via GPO is not an option thanks)

Posted

Two files are needed, one to delete all printers, then one to install based on computer name

cscript \\quartz\profiles\printers\_delete_prn.vbs

cscript \\quartz\profiles\printers\vbs\%computername%.vbs

 

delete_prn.vbs

 

strComputer = "."

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

 

Set colInstalledPrinters = objWMIService.ExecQuery _

("Select * From Win32_Printer Where Network = True")

 

For Each objPrinter in colInstalledPrinters

objPrinter.Delete_

Next

 

------------------

 

ajw101.vbs

 

On Error resume Next

set objNetwork = WScript.CreateObject("WScript.Network")

set objShell = WScript.CreateObject("WScript.Shell")

 

'Add Network printers

objNetwork.AddWindowsPrinterConnection "\\quartz\HP LaserJet P2055dn IT01 P1"

objNetwork.AddWindowsPrinterConnection "\\quartz\HP Colour LaserJet CP2025 IT01"

objNetwork.AddWindowsPrinterConnection "\\quartz\Konica Minolta 421 STAFFROOM"

 

'Set Default Printer

objNetwork.SetDefaultPrinter "\\quartz\HP LaserJet P2055dn IT01 P1"

 

Hope that helps

Andrew

  • Thanks 1
Posted (edited)

We're not using this any more (We're using this instead but this is what we used to use:

 

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("Shell.Application")

For i = 0 to oPrinters.Count - 1 Step 2
           On Error Resume Next
    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
            	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
		WScript.Echo("Printer No. " & i & " removed")
'			WScript.Sleep(250)	
           else WScript.Echo "No network printers found"
           end if
Next
	WScript.Echo("All existing printer mappings removed")

Select Case (Left(clientName, 4))

Case "e057"
	WshNetwork.AddWindowsPrinterConnection "\\printserver1\E057A"
	WScript.Echo("E057A Printer Added")
'		WScript.Sleep(250)
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\E057-A*COLOUR"
	WScript.Echo("E057-A*COLOUR Printer Added")
'		WScript.Sleep(250)
	WshNetwork.SetDefaultPrinter "\\printserver1\E057A"
	WScript.Echo("Default Printer Set")
'		WScript.Sleep(250)

Case "e060"
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\E060-L*"
	WScript.Echo("E060-L* Printer Added")
'		WScript.Sleep(250)
	WshNetwork.SetDefaultPrinter "\\printserver1\E060-L*"
	WScript.Echo("Default Printer Set")
'		WScript.Sleep(250)

Case "s110"
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\S110-L*"
	WScript.Echo("S110-L* Printer Added")
'		WScript.Sleep(250)
	WshNetwork.SetDefaultPrinter "\\printserver2\S110-L*"
	WScript.Echo("Default Printer Set")
'		WScript.Sleep(250)

Case "s107"
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\S110-L*"
	WScript.Echo("S110-L* Printer Added")
'		WScript.Sleep(250)
	WshNetwork.SetDefaultPrinter "\\printserver2\S110-L*"
	WScript.Echo("Default Printer Set")
'		WScript.Sleep(250)


Case "s023"
	WshNetwork.AddWindowsPrinterConnection "\\printserver1\S023L"
	WScript.Echo("S023A* Printer Added")
'		WScript.Sleep(250)
	WshNetwork.SetDefaultPrinter "\\printserver1\S023L"
	WScript.Echo("Default Printer Set")
'		WScript.Sleep(250)

' This case statement was used on a Windows XP machine to design and troubleshoot the script
Case "xp53"
	WScript.Echo("This client is called " & clientName)
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\C015-A*"
	WScript.Echo("C015-A* Printer Added")
	Wscript.sleep(250)
 	WshNetwork.AddWindowsPrinterConnection "\\printserver2\E029-L*"
	WScript.Echo("E029-L* Printer Added")
	Wscript.sleep(250)
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\N005-L*"
	WScript.Echo("N005-L* Printer Added")
	Wscript.sleep(250)
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\S035-AA"
	WScript.Echo("S035-AA Printer Added")
	Wscript.sleep(250)
	WshNetwork.AddWindowsPrinterConnection "\\printserver2\W010-A*"
	WScript.Echo("W010-A* Printer Added")
	Wscript.sleep(250)
	WshNetwork.SetDefaultPrinter "\\printserver2\S035-AA"
	WScript.Echo("Default Printer Set")
	wscript.sleep(250) 		

End Select

 

That gets the first four characters of the machine name, converts it to lower case and maps different printers depending on the result.

 

I just chopped that out of the script which did quite a lot more but that should work OK.

Edited by Norphy
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...