Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2004-04-07
Medium Priority
Last Modified: 2012-05-04
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!
Question by:stevestark
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

ketelhuis earned 672 total points
ID: 10777145

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.


LVL 85

Assisted Solution

oBdA earned 664 total points
ID: 10801196
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

Assisted Solution

haresh-nyc earned 664 total points
ID: 10818771
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.

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question