Assigning printers based on location and user after logging in through a VPN connection.

Clients:  Windows 2000/XP
Server:  Windows 2003 AD

Here is the process:  The user boots up the PC/Laptop.  They are presented with the CTRL-ALT-DEL screen.  When the user hits CTRL-ALT-DEL they are presented with the Cisco VPN 4.0+ version client login.  Once logged into the VPN, they can then log in to the OS where login scripts can then run.

Setup after logging in:  If it is the first time a user logs in to that PC, they do not have printers installed.  We have instructed everyone on how to simply add the printers, but they normally forget and then complain about it.

Goal:  We would like to use a login script to set up the printers automatically based on the user and the location of the user.  We have users that float between sites and need sometimes 3 printers installed at each site.  I am using the following script to automatically install the printers, but this installs the exact printers no matter which site they are located at:

REM This script adds a printer without the need of Add a Printer Wizard
REM It then sets the first printer added as the default printer
rundll32 printui.dll,PrintUIEntry /in /n \\server\printer
rundll32 printui.dll,PrintUIEntry /y /n "\\server\printer"

This script would be perfect if it weren't for the floating users.  

I would normally do this at the system level through group policy, but they do not receive the group policy when booting up because they must first connect to the Cisco VPN.  This limits my ability to deploy this via a script with the exception of a user login script.  

Any help would be appreciated.  Big points!
Who is Participating?

Improve company productivity with a Business Account.Sign Up

ketelhuisConnect With a Mentor Commented:

When you use kix, you can retrieve the ip-adsress of the users pc and, based on the ip-address, assign printers.

This off course only works when different sites have different subnets.


oBdAConnect With a Mentor Commented:
That script should work for you; it calculates the current subnet the user logs in from. All you have to do is add the labels and configure the printer mapping, as configured in the two example subnets. Note that the "real" subnet is calculated from the subnet mask, it's not just based on the IP octets!
Instead of the rundll32 command you're using, you can use con2prt.exe from the Zero Administration Kit as well; I like it better since, unlike the "rundll32 printui", it's a real command line tool.
If you need to map printers according to group membership, you can use the free ifmember.exe tool.

@echo off
for /f "tokens=3-6 delims=:. " %%a in ('ipconfig ^| find /i "IP Address"') do (
  set IP1=%%a
  set IP2=%%b
  set IP3=%%c
  set IP4=%%d
set IPAddress=%IP1%.%IP2%.%IP3%.%IP4%
for /f "tokens=3-6 delims=:. " %%a in ('ipconfig ^| find /i "Subnet"') do (
  set /a SN1=%IP1% ^& %%a
  set /a SN2=%IP2% ^& %%b
  set /a SN3=%IP3% ^& %%c
  set /a SN4=%IP4% ^& %%d
set Subnet=%SN1%.%SN2%.%SN3%.%SN4%

echo Current IP address: %IPAddress%
echo Current Subnet:     %Subnet%
:: *** Check if the label for the subnet exists; if not, leave:
type "%~f0" | find ":[%Subnet%]" >NUL
if errorlevel 1 goto leave
goto :[%Subnet%]

:: *** Handle the different subnets:

echo Mapping printers for %Subnet%:
con2prt.exe /c \\Subnet1PrintServer\Printer
goto leave

echo Mapping printers for %Subnet%:
con2prt.exe /c \\Subnet2PrintServer\Printer
goto leave


How to Use Con2prt.exe to Connect to a Network Printer

Zero Administration Kit

Resource Kits Free Tool Downloads: Ifmember.exe
haresh-nycConnect With a Mentor Commented:
if the printer names are the same in each locaction,
you can take advantage of the user environment variable    LOGONSERVER.

what happens if you use the following:

rundll32 printui.dll,PrintUIEntry /in /n \\%logonserver%\printer1
rundll32 printui.dll,PrintUIEntry /y /n " \\%logonserver%\printer2

I'm assuming each user should by default become authenticated by the closest server to them,
and therefore the logonserver should be their local DC at that site.

please update us on the status.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.