Solved

Mapping printer from a logion script by ip address

Posted on 2007-03-27
20
468 Views
Last Modified: 2010-04-20
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
0
Comment
Question by:advmicro
  • 12
  • 8
20 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18802802
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.

http://www.experts-exchange.com/Networking/Misc/Q_21101041.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

0
 

Author Comment

by:advmicro
ID: 18805343
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!
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 18806723
OK lets say we'll use the login script method.  You should be able to do something like this.  Try it out manually by saving as a batch file (printsetup.cmd say) and run it locally on a machine.  Remove the @echo off from the top to see what it is doing more clearly for testing.

Post back any issues.

hth

Steve

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

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 \\subnet2SERVER\PRINTERNAME
  rundll32 printui.dll,PrintUIEntry /in /n /y \\subnet1server\PRINTERNAME

goto next

:subnet2
  echo Running on subnet 2 (%subnet%) from %ipaddr%
  rundll32 printui.dll,PrintUIEntry /dn /n \\subnet1SERVER\PRINTERNAME
  rundll32 printui.dll,PrintUIEntry /in /n /y \\subnet2server\PRINTERNAME

goto next

:next
:end

0
 

Author Comment

by:advmicro
ID: 18807320
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18807758
Odd.  I'll give it a try later on my own kit, at work at the moment.

Steve
0
 

Author Comment

by:advmicro
ID: 18816515
Did you get a chance to test that out yet?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18817519
Sorry, have been busy.  Will look soon as  i can and update here.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18822108
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18823131
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
0
 

Author Comment

by:advmicro
ID: 18823158
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
0
Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

 

Author Comment

by:advmicro
ID: 18823205
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.
0
 

Author Comment

by:advmicro
ID: 18823569
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.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18823769
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
0
 

Author Comment

by:advmicro
ID: 18824306
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.

0
 

Author Comment

by:advmicro
ID: 18824314
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
0
 

Author Comment

by:advmicro
ID: 18824349
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.
0
 

Author Comment

by:advmicro
ID: 18824359
btw, the "lewiston-server"  and "Saco" are  Windows 2000 Servers
0
 

Author Comment

by:advmicro
ID: 18824461
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 .
0
 

Author Comment

by:advmicro
ID: 18833639
Is anyone available to figure this out? I made the question answered, but it is not
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18840005
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

My previous article  (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html)detailed one possible method to get SCCM 2007 installed an…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now