Discussion:
adding printer depending on username
(too old to reply)
nico
2009-05-15 22:20:29 UTC
Permalink
Hello,

I want to add a printer on the WS through a script according to the
machinename on wich the user logs on.

ex. if user logs on to WS A06-12 I want to install printer A06
if user logs on to WS B01-15 I want to install printer B01
if user logs on to WS B03-34 I want to install printer B03

Is this possible through a logonscript and how.
Where can i find a list of the builtin variables (%username%) that i can use
in a script

regards,
N.
Richard Mueller [MVP]
2009-05-16 01:47:11 UTC
Permalink
Post by nico
Hello,
I want to add a printer on the WS through a script according to the
machinename on wich the user logs on.
ex. if user logs on to WS A06-12 I want to install printer A06
if user logs on to WS B01-15 I want to install printer B01
if user logs on to WS B03-34 I want to install printer B03
Is this possible through a logonscript and how.
Where can i find a list of the builtin variables (%username%) that i can
use in a script
regards,
N.
A VBScript logon script can use the wshNetwork object to retrieve the name
of the user and computer, then connect to the appropriate printer. For
example:
========
Option Explicit
Dim objNetwork, strUserName, strComputer

' Retrieve user and computer names.
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.UserName
strComputer = objNetwork.ComputerName

' Map printer based on computer name.
Select Case strComputer
Case "A06-12"
objNetwork.AddWindowsPrinterConnection "\\PrintServer\A06"
Case "B01-15"
objNetwork.AddWindowsPrinterConnection "\\PrintServer\B01"
Case "B03-34"
objNetwork.AddWindowsPrinterConnection "\\PrintServer\B03"
End Select
======
If you want to parse the computer name to determine the printer you can use
code similar to below:
========
Option Explicit
Dim objNetwork, strUserName, strComputer, strPrinter

' Retrieve user and computer names.
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.UserName
strComputer = objNetwork.ComputerName

' Use left three characters of computer name
' to identify the printer.
strPrinter = Left(strComputer, 3)

objNetwork.AddWindowsPrinterConnection "\\PrintServer\" & strPrinter
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
nico
2009-05-19 08:15:30 UTC
Permalink
Post by Richard Mueller [MVP]
Post by nico
Hello,
I want to add a printer on the WS through a script according to the
machinename on wich the user logs on.
ex. if user logs on to WS A06-12 I want to install printer A06
if user logs on to WS B01-15 I want to install printer B01
if user logs on to WS B03-34 I want to install printer B03
Is this possible through a logonscript and how.
Where can i find a list of the builtin variables (%username%) that i can
use in a script
regards,
N.
A VBScript logon script can use the wshNetwork object to retrieve the name
of the user and computer, then connect to the appropriate printer. For
========
Option Explicit
Dim objNetwork, strUserName, strComputer
' Retrieve user and computer names.
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.UserName
strComputer = objNetwork.ComputerName
' Map printer based on computer name.
Select Case strComputer
Case "A06-12"
objNetwork.AddWindowsPrinterConnection "\\PrintServer\A06"
Case "B01-15"
objNetwork.AddWindowsPrinterConnection "\\PrintServer\B01"
Case "B03-34"
objNetwork.AddWindowsPrinterConnection "\\PrintServer\B03"
End Select
======
If you want to parse the computer name to determine the printer you can use
========
Option Explicit
Dim objNetwork, strUserName, strComputer, strPrinter
' Retrieve user and computer names.
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.UserName
strComputer = objNetwork.ComputerName
' Use left three characters of computer name
' to identify the printer.
strPrinter = Left(strComputer, 3)
objNetwork.AddWindowsPrinterConnection "\\PrintServer\" & strPrinter
great stuff,
thank you very much!

N.

Loading...