Avatar of advmicro
advmicro

asked on 

Mapping printer from a logion script by ip address

I  have two servers. One on 192.168.1.x and 192.168.2.x. Each server is in a different location. I need to create a login script that will map the appropriate printer for the ip address. For example, a client logs in at one location and gets a  printer, currently, and then, if they go to the other location that printer is still there. I need to make it so it adds the printer for that location ONLY so they wont be printing to the wrong location. In addition, I need to make that the printer default.

Can anyone help?

Thanks
Microsoft Server OSMicrosoft DOSWindows Server 2003

Avatar of undefined
Last Comment
Steve Knight
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

If this is active directory you could perhaps look at Site login scripts for starters.  You assign two different sites in AD Sites & services and define a subnet for each.  Then each time a user logs in from an IP in that site the group polcies for that site are processed.  You can assign a login script to the site in that way.

The alternative is to parse the output of ipconfig to get the IP address in a script, e.g.

for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IP Address"') do set IP ADDR=%%a
for /f "tokens=1,2,3 delims=." %%a in ("%ipaddr%") do set SUBNET=%%a.%%b.%%c

Which leaves the last IP address (if more than one) in the IPADDR variable and the first three octets of it in the variable SUBNET

Having got to that point you know which subnet you are on and can sort out the printers.  Adding a printer you can use VBScript or a simple command from batch file:

rundll32 printui.dll,PrintUIEntry /in /n \\SERVER\MYPRINTERNAME

There are details of all the command line switches for this here along with a sample of the VBS way of doing it.

https://www.experts-exchange.com/questions/21101041/Printers-by-login-script.html

You can use /dn to delete a network printer then use /in to install the correct network printer.

One other cleverish way... If your printer is shared from a domain controller in each office and the share name is the same then you can connect the user to \\domainname.com\printer and it should print to the local one regardless - can't say I've tried that... it should work though as DNS will always give the nearest dc's IP out for \\domainname.com.

Anyway give some of that a try and come back if you want more help.

Steve

Avatar of advmicro
advmicro

ASKER

Alright.
Assume I am not so familiar with scripting.
I understand the first part and the second part. However, how do I put it together(for example) How do I have one printer added recognizing that your on 192.168.1.x versus 192.168.2.x.

Let me know if I was unclear in that response.
Thank You!
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of advmicro
advmicro

ASKER

I like that. However, I get these UNC path not supported messages. I went in to the registry and changed that, however it looks like I'd have to change that on every workstation. Although, it still did not work. I runs and does nothing at all.

I do greatly appreciate the help and assistance.
Thank You
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Odd.  I'll give it a try later on my own kit, at work at the moment.

Steve
Avatar of advmicro
advmicro

ASKER

Did you get a chance to test that out yet?
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Sorry, have been busy.  Will look soon as  i can and update here.

Steve
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Hmm, which but isn't working.  On my XP laptop the rundll32 lines workfine to install the printer from a Windows server and set the correct one as default.  Try the commands manually to see what is going on here perhaps?

Are the printers actually installed and shared from a Windows server or are you trying to connect them directly with a local printer on each machine directly to the printers?

Steve
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Did you get this working then?  Curious for my own knowledge why it wouldn't work for you but does for me and others?

Steve
Avatar of advmicro
advmicro

ASKER

It has not worked yet. Here is what I am using. I have two windows servers running and the printers are directly connected to those. The other computers are going to be connected via the network. here is what your source looks like after I made a few changes, could anything I have here be wrong.

@echo off

for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IP Address"') do set IP ADDR=%%a
for /f "tokens=1,2,3 delims=." %%a in ("%ipaddr%") do set SUBNET=%%a.%%b.%%c

if "%subnet%"=="192.168.1" goto subnet1
if "%subnet%"=="192.168.2" goto subnet2

echo On another subnet (%subnet%)
goto next

:subnet1
  echo Running on subnet 1 (%subnet%) from %ipaddr%
  rundll32 printui.dll,PrintUIEntry /dn /n \\saco\HP4200
  rundll32 printui.dll,PrintUIEntry /in /n /y \\lewiston-server\HP4200

goto next

:subnet2
  echo Running on subnet 2 (%subnet%) from %ipaddr%
  rundll32 printui.dll,PrintUIEntry /dn /n \\lewiston-server\HP4200
  rundll32 printui.dll,PrintUIEntry /in /n /y \\saco\HP4200

goto next

:next
:end
Avatar of advmicro
advmicro

ASKER

I was unclear about what to change for this -

rem Your existing logon script
net use h: \\server\share
rem etc.


So I got rid of it.
Avatar of advmicro
advmicro

ASKER

Any ideas?
Sorry for the rush....
The urgency of this solution is a bit greater, since the client is continuing to call about this fix.

Just whenever you have a chance let me know....
In a moment I will run another test and see what the error is and re-post that.
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

The first bit was just inferring you should add the rest onto the end of your existing login script that maps any drives or anything else.

If you can let us know what the errors are will take a look.  If you can't see the script running for some reason add

>>%userprofile%\desktop\logfile.txt   2>> &1

to the end of any lines that may be a problem and it will dump a log file into the user's desktop folder with results of running each line.

Steve
Avatar of advmicro
advmicro

ASKER

I run the script and the command prompt prompts for only a quick moment.
Then nothing happens.
I included the code to get a log file but that did not work either.

Avatar of advmicro
advmicro

ASKER

my apologies.
UNC paths are not supported < Is an error I am getting.
Although, I think i can get around that which is what I have donebut I do not think that it works stil. Again, I will try another test though
Avatar of advmicro
advmicro

ASKER

OK, another correction. That error only shows if I run the script from the netlogon shared folder. If I copy the .bat to my desktop and run it. Than it does not work and it does not show any error.
Avatar of advmicro
advmicro

ASKER

btw, the "lewiston-server"  and "Saco" are  Windows 2000 Servers
Avatar of advmicro
advmicro

ASKER

and the logon script is on a shared folder of a Windows2003 server.

I am  just trying to list to you all of the possible variables to get this to work .
Avatar of advmicro
advmicro

ASKER

Is anyone available to figure this out? I made the question answered, but it is not
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

The question is marked as answered so no-one else is likely to look.  You can have it re-opened if you like by posting a q at community support.

Meanwhile, run the script manually without the @echo off and post back the results here please.  When I ran the script myself using my own printer names the default printer changed as expected.

Steve
Windows Server 2003
Windows Server 2003

Windows Server 2003 was based on Windows XP and was released in four editions: Web, Standard, Enterprise and Datacenter. It also had derivative versions for clusters, storage and Microsoft’s Small Business Server. Important upgrades included integrating Internet Information Services (IIS), improvements to Active Directory (AD) and Group Policy (GP), and the migration to Automated System Recovery (ASR).

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo