Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > adding printer depending on username

Reply
Thread Tools Display Modes

adding printer depending on username

 
 
nico
Guest
Posts: n/a

 
      05-15-2009
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.


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      05-16-2009

"nico" <> wrote in message
news:...
> 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
--


 
Reply With Quote
 
nico
Guest
Posts: n/a

 
      05-19-2009
Richard Mueller [MVP] schreef:
> "nico" <> wrote in message
> news:...
>> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XP desktop printer networked to VISTA laptop - adding printer error Patrycja Windows Vista Printing / Faxing / Scanning 1 04-19-2008 11:34 AM
Username/Password Requests When Sharing Printer & Files From w2K Server To XP Kevin Server Networking 0 10-06-2005 03:13 PM
adding another username Greg Active Directory 2 01-10-2005 06:01 PM
Printer connection depending of computerlocation AndersTW Scripting 2 10-01-2004 06:41 AM
Adding user to group with # in username jeepers Scripting 4 05-29-2004 03:00 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59