Home All Groups Group Topic Archive Search About

adding printer depending on username

Author
15 May 2009 10:20 PM
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.

Author
16 May 2009 1:47 AM
Richard Mueller [MVP]
Show quote Hide quote
"nico" <nospam@hotmail.com> wrote in message
news:eWniata1JHA.4632@TK2MSFTNGP02.phx.gbl...
> 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
--
Author
19 May 2009 8:15 AM
nico
Richard Mueller [MVP] schreef:
Show quoteHide quote
> "nico" <nospam@hotmail.com> wrote in message
> news:eWniata1JHA.4632@TK2MSFTNGP02.phx.gbl...
>> 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
>
great stuff,
thank you very much!

   N.