Link to home
Start Free TrialLog in
Avatar of OnsiteSupport
OnsiteSupport

asked on

Logon Script - map printers based on location

Depending on which DC users logon from (they are in different locations on different subnets, of course)....
can I map printers based on where users logon location?

If I'm in LA, map LA printers
If I'm in NYC, map NYC printers.  I don't want them getting printer connections and then printing to the mystery printer cross country LOL

Thanks
Avatar of beechy_
beechy_
Flag of United Kingdom of Great Britain and Northern Ireland image

If your servers are 2003 R2 or later you can use group policy to deploy printers and set the policies on your site objects to deploy different printers to different locations.

http://www.windowsnetworking.com/articles_tutorials/Deploying-Printers-Group-Policy-Windows-R2.html
First you'll have to make sure that your administrators in LA and NYC grant the user permission the the shared resource.

A little more involved that but I think I've covered all you need:
1. Get IP address of machine
2. Determine Location
3. Check if printer is already referenced on the machine and if not install it
4. Set the printer as default printer

You'll have to do a little reading; I didn't want to plagiarize some one else's work so links to different scripts are within the script posted below.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Your script will have to do the following:

//Get the IP address of the machine the user is logging into the network with:

DIM IPLocation

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set IPConfigSet = objWMIService.ExecQuery _

    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
 
For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then

        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)

            WScript.Echo IPConfig.IPAddress(i)

        //Determine if IP address in in LA or NYC
 //Convert IPConfig.IPAddress(i) to Binary  SEE HERE: http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/

        if BinaryIP > NYCBinaryIPS and < NYCBinaryIPS then
       
          IPLocation = NYC
        else
     
         IPLocation = LA
        end if
 
           Select Case IPLocation
         
           Case LA
               //Check if LA printer is already installed If not install it.
               //See Here: http://www.tek-tips.com/viewthread.cfm?qid=551578&page=1
               //Set as default printer
              //See Here: http://www.computerperformance.co.uk/Logon/LogonScript_Printer_Bonus.htm
            Case NYC
               //Check if NYC Printer is already installed if not install it.
              //See Here: http://www.tek-tips.com/viewthread.cfm?qid=551578&page=1
              //Set as default printer
              //See Here
           
          End Select
        Next
    End If
Next



Avatar of greg ward
Or you could use this

Option Explicit
Dim objPrinters, objShell, objNetwork, strUNCPrinter1, strUNCPrinter2
 
ON ERROR RESUME NEXT
 
Set objPrinters = WScript.CreateObject("WScript.Network")
Set objShell = WScript.CreateObject("WScript.Shell")
 
 
strUNCPrinter1 = "\\server\printer"
strUNCPrinter2 = "\\server\printer"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter1
 
WScript.Quit
 
copy the file using unc to the all users start up folder and everyone gets the right printer and it gets a default one too.
 
Greg
Avatar of OnsiteSupport
OnsiteSupport

ASKER

Greg-
what is calculating which printer they should get?
strUNCPrinter1 = "\\server\printer"
change to
strUNCPrinter1 = "printserver\printershare"
Greg
 
ASKER CERTIFIED SOLUTION
Avatar of OnsiteSupport
OnsiteSupport

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Have you tried using Group Policy preferences?  You can do a target by IP Address range and you can also set the default printer based on their location (through IP address).
Assuming that NYC and LA branches have different subnets (should be).

Check this out.

http://www.grouppolicy.biz/tag/printer/

For group policy preferences, you can check out this link

http://www.windowsnetworking.com/articles_tutorials/Group-Policy-Preferences-Get-Them-Running-Today.html
maco-
Looks like this is only available on Windows Server 2008...am I correct?
nope. u only need vista or higher OS version to manage it and see the option. domain can be 2k3 and u just need to install the extensions on clients lower than vista.
Maco....extensions...can you point me to the right documentation for this piece?
http://www.windowsnetworking.com/articles_tutorials/Group-Policy-Preferences-Get-Them-Running-Today.html

This article is pretty good and explains everything.  As what he said (never tried though) you can even use this on a 2k domain.  Just check the part "Getting the CSE Installed Correctly" for instructions.   You can download the KB links and install it manually or use WSUS to install it automatically (just search group policy extension).

First you need to have at least a vista workstation, you don't need to have a 2k8 server to do this, then install GPMC on your vista or windows 7.  You should be able to see "Preferences" through vista/windows 7 gpmc.

Here's the article on how to install GPMC/RSAT on vista.
http://www.windowsecurity.com/articles/Installing-Using-Remote-Server-Administration-Tools-RSAT-Vista.html
Hi
This script just sits on the machine in the all users start up and does not require domain membership.
 
Greg