Jump to content

Recommended Posts

Posted

Hi All,

 

I am trying to create a simple printer logon script in VBS.

 

MY GOAL;- To create a logon script that queries the computer name and adds a network printer and installs the appropriate print driver.

 

Example;- If Computer name is A031-01-390 then add printer A031-Printer.

 

I am about as much use as tits on fish when it comes to vbs. I have looked through a few websites and managed to cobble together something;-

 

Set WshNetwork = WScript.CreateObject("WScript.Network")
If (Left(WshNetwork.ComputerName, 4) = "A051") Then
Dim objNetwork, strUNCPrinter, strPrnDrv
strUNCPrinter = "\\SERVERNAME\A051-Printer"
strPrnDrv = "HP Color LaserJet CP3525 PCL6"


Set objNetwork = CreateObject("WScript.Network") 
objNetwork.AddWindowsPrinterConnection strUNCPrinter, strPrnDrv


WScript.Quit


end if

 

So above I have managed to add a printer in the logon script. Now what I need to do is make it add different printers for different computers. I tried using the same code but before the 'end if' I tried doing 'else' and its just broken everything down. I dont have a good enough grasp of vbs to get it to work. tried reading up and just getting frustrated. looked at sample scripts but would prefer they came from a location like this.

Posted (edited)

Hi,

 

We use VBA for our printer scripts.

When a user logges in the main login script does the following.

 

set printerscript="\\blabla\e$\%computername%.vbs"

start /wait %printerscript%.

 

Then we have a script for each machine in the school. The VBA Script firstly checks for a local printer and will set

that as the default if one is present. Otherwise it will look for the network printers.

 

Script:

On Error Resume Next
Dim Local
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colprinters = objWMIService.ExecQuery("Select * from Win32_Printer")
local="FALSE"
for each cPrinter in colprinters
if cprinter.local = TRUE then
local="TRUE"
ELSE
cprinter.delete_
END IF
NEXT
WshNetwork.AddWindowsPrinterConnection "\\server\print1"
WshNetwork.AddWindowsPrinterConnection "\\server\print2"
WshNetwork.AddWindowsPrinterConnection "\\server\print3"
if local="FALSE"then
WshNetwork.SetDefaultPrinter "\\server\defaultprinter"
END IF
WScript.quit

Edited by johnhart96
  • Thanks 1
Posted
cheers for the reply. This is something I had though about however this would require a number of scripts, this is a possibility but I would like to do it with the one. Also does your script install the relevant drivers?

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...