Printer Mapping by Subnet

After a user logs into and authenticates to a particular physical location (all one subnet...10.203.X.X), can a separate script be run to install all of the printers at that location? In that way, any person logging into a computer on that subnet, could utilize any printer at that location.

Computers on this subnet authenticate to one of 2 DC's. Only computers on this subnet authenticate to these 2 DC's. If that info is helpful.
amfioreAsked:
Who is Participating?
 
Fatal_ExceptionConnect With a Mentor Commented:
I take it that some users have portable laptops, and you cannot assign printers based on the computers themselves..?

Then you might be able to use this:  (I forget where I got it, but have it in one of my knowledge bases)...  :)

Create a single login script that checks the Subnet that the user is on and, based upon the Subnet (the 3rd octet in the IP Address) map a network drive or printer specific to that location.

Below is a simple batch file that determines the Subnet and maps a drive based on the Subnet.

 @echo off
cls

REM LOGIN.BAT
REM Default Login Script
REM
REM NOTE: When calling other batch files from this login script,
there are two important things to keep in mind.
REM       - always be sure to use 'call' before the batch file name
REM       - never use 'exit' in the batch file that you are calling
REM       Failure to keep these things in mind will cause this login
script to terminate after calling.
REM       the other batch file.

if exist c:tempip.tmp del c:tempip.tmp

echo Running Windows Login Script...
echo.
echo Temporarily removing F drive...
echo.
net use f: /delete

REM Determine Subnet, do things based on SUBNET
REM ALL USERS section is where things go that need to happen for all
users regardless of subnet.
REM
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| find /i "IP Address"')
do set IP=%% iecho %IP% >> c:tempip.tmp
for /f "tokens=3 delims=." %%j in (c:tempip.tmp) do set SUBNET=%%j

if %SUBNET%==16 goto 16_SUBNET
if %SUBNET%==100 goto 100_SUBNET
if %SUBNET%==250 goto 250_SUBNET
goto ALL_USERS

:16_SUBNET
net use F: \{16_subnet_server}share
echo Welcome to the 16 subnet!
goto ALL_USERS

:100_SUBNET
net use F: \{100_subnet_server}share
echo Welcome to the 100 subnet!
goto ALL_USERS

:250_SUBNET
net use F: \{250_subnet_server}share
echo Welcome to the 250 subnet!
goto ALL_USERS

:ALL_USERS
REM Use this section to perform functions that pertain to all users
goto END

:END
0
 
Fatal_ExceptionCommented:
I might look at this from a different perspective... being that I would place those users in a separate OU and run the printer script using a GPO on that OU...  JMHO...
0
 
amfioreAuthor Commented:
Here's the issue. There are over 6000 users who intermittently go to this location for classes, etc. They need to print when they are there and cannot. But, I wouldn't want them to have access to those printers all the time. Some users print confidential materials, and forgot to "pick" the correct printer.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Fatal_ExceptionCommented:
BTW:  that script maps a drive, but you can change it to map printers...
0
 
amfioreAuthor Commented:
I found this on experts-exchange, but i'm new to scripting and really don't understand it. Where do I customize this? anything you can do to help would be appreciated.

All I am trying to do is if a user is in 10.203.x.x - map to

rundll32 printui.dll,PrintUIEntry /in /n\\sps-printserv\HS-COLOR
rundll32 printui.dll,PrintUIEntry /in /n\\sps-hs-apps\Rm-259-office
rundll32 printui.dll,PrintUIEntry /in /n\\sps-hs-apps\Rm-259-color
rundll32 printui.dll,PrintUIEntry /in /n\\sps-hs-apps\Rm-427-lab
rundll32 printui.dll,PrintUIEntry /in /n\\sps-hs-apps\Rm-421-office
rundll32 printui.dll,PrintUIEntry /in /n\\sps-hs-apps\Rm-400-office
0
 
Fatal_ExceptionCommented:
/in = add network printer connection
/n = PrinterName

But, I came across a nice script that was posted in the Petri forums:

http://www.petri.co.il/forums/archive/index.php?t-7759.html

BAT FILE:

===========copy==============

:GetIP
:: IP for primary adapter
setlocal
for /f "delims=: tokens=1-2" %%c in ('ipconfig /all ^| find "IP Address"') do set GetIP=%%d
endlocal & set GetIP=%GetIP:~1%

start /w logon.vbs %GetIP%



VbScript: logon.vbs


Option Explicit

Dim MyIP, SubNet, IpChunk

On Error Resume Next

Set wshNetwork = CreateObject("WScript.Network")

MyIP = Wscript.Arguments.item(0)

IpChunk = Split(MyIP,".")
SubNet = CInt(IpChunk(2))

'Assuming IP's 192.168.1.0, 192.168.2.0, 192.168.3.0....
If SubNet = 1 Then Floor1
If SubNet = 2 Then Floor2
If SubNet = 3 Then Floor3

Public Sub Floor1
'add your code here
wshNetwork.MapNetworkDrive "M:", "\\Server\NET-APPS"
wshNetwork.AddWindowsPrinterConnection "\\Server\HPLJ4200-flr1"
wshNetwork.RemovePrinterConnection "\\Server\HPLJ4200-flr2"
wshNetwork.RemovePrinterConnection "\\Server\HPLJ4200-flr3"
End Sub

Public Sub Floor2
wshNetwork.MapNetworkDrive "M:", "\\Server\NET-APPS"
wshNetwork.AddWindowsPrinterConnection "\\Server\HPLJ4200-flr2"
wshNetwork.RemovePrinterConnection "\\Server\HPLJ4200-flr1"
wshNetwork.RemovePrinterConnection "\\Server\HPLJ4200-flr3"
End Sub

Public Sub Floor3
wshNetwork.MapNetworkDrive "M:", "\\Server\NET-APPS"
wshNetwork.AddWindowsPrinterConnection "\\Server\HPLJ4200-flr3"
wshNetwork.RemovePrinterConnection "\\Server\HPLJ4200-flr1"
wshNetwork.RemovePrinterConnection "\\Server\HPLJ4200-flr2"
End Sub

Wscript.quit
0
 
Fatal_ExceptionCommented:
BTW:  I am not well versed with doing my own scripting either...  Lucky I have a separate programming dept. that I can lean on with this at my corp. offices..  :)
0
 
amfioreAuthor Commented:
Surprisingly, I got the first script to work. Thank you very much. I'll try this one as well.
0
 
Fatal_ExceptionCommented:
Great news!  Am going to try it myself as soon as I get back in the office..  and thank you..

FE
0
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.