Often times network admins need to run domain logon scripts for seperate subnets, but also for a seperate set of computers within that subnet. In this circumstance, configuring Active Directory Sites and Services then linking a GPO to site/subnet might not be an option.
So now what ?
This is a real world example of this situation and my accepted solution:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Q_22746765.html?sfQueryTermInfo=1+locat+login+script+vb
This is the solution you can employ so that your logon scripts can identify the subnet a computer exists on...in order to decide whether to run or terminate. Currently the script is only designed for class C network identification.
You need two things to make this work...
1) The attached vbscript (paste into notepad and save as *.vbs)
2) A program called setx.exe (Found in the MS Resource kit -
http://www.microsoft.com/downloads/details.aspx?FamilyID=DC2D3339-8F36-4FBA-A406-2A2A2AD7208C&displaylang=en)
Once you have successfully employed this method....you can use the conditional code in your logon scripts using the subnet as a system variable.
Example: The subnet is 192.168.6, which was set as a variable %IPNETID%, and I want a script to only run if that is the subnet the machine is presently on...
Therefore the first line on the logon batch script would be the following....
IF NOT %IPNETID% == 192.168.6 EXIT
or you could use this...
IF %IPNETID% == 192.168.6 net use m: "\\server\share"
This is my original solution which was published on Microsoft Script Center repository - Technet (
http://www.microsoft.com/technet/scriptcenter/csc/scripts/desktop/settings/cscds060.mspx)
Now when you move machines between subnets, the proper logon scripts will run automatically after the first reboot.
NOTE: One caveat i've found, is that this script when used as a startup script will sometimes set the system variable only after the second reboot/logon, on a newly domain-joined machine. I believe this is because of machine authentication reasons... not sure though. Make sure the setx file is accessible to all machines, and that this script is set to run prior to other scripts running because the variable needs to be set prior to being used as a condition in your other logon scripts.
Comments (3)
Author
Commented:Commented:
Set Prompt=$D$T $B$G
::Deployment Script
::Version: 11.3
::Created by: DuaneMizell (https://www.experts-exchange.com/M_4688963.html)
::Created: 12/2009
::Modified: 03/2012
for /f "tokens=2 delims=[]" %%i in ('pathping -p 1 -q 1 -4 %computername%') do set IP=%%i
for /f "tokens=2 delims=." %%i in ('echo %IP%') do set OCTET2=%%i
set strIP=%OCTET2%
if ["%strIP%"]==["14"] (
echo 14th Floor IP address...
goto 14Office)
if ["%strIP%"]==["15"] (
echo 15th Floor IP address...
goto 15Office)
if ["%strIP%"]==["16"] (
echo 16th Floor IP address...
goto 16Office)
if ["%strIP%"]==["18"] (
echo 18th Floor IP address...
goto 18Office)
if ["%strIP%"]==["23"] (
echo 23trd Floor IP address...
goto 23Office)
if ["%strIP%"]==["24"] (
echo 24th Floor IP address...
goto 24Office)
if ["%strIP%"]==["25"] (
echo 25th Floor IP address...
goto 25Office)
Echo Not a good IP address: 10.%strIP%.x.x (This computers IP address is: %IP%) Automatically pulling files from home office!!!
goto DefaultInstall
:14Office
@Echo On
::DO: Stuff
set InstallPath="\\SomeServer\
goto Install
:15Office
@Echo On
::DO: Stuff
set InstallPath="\\SomeServer1
goto Install
:16Office
@Echo On
::DO: Stuff
set InstallPath="\\SomeServer2
goto Install
:18Office
@Echo On
::DO: Stuff
set InstallPath="\\SomeServer3
goto Install
:23Office
@Echo On
::DO: Stuff
set InstallPath="\\SomeServer4
goto Install
:24Office
@Echo On
::DO: Stuff
set InstallPath="\\SomeServer5
goto Install
:25Office
@Echo On
::DO: Stuff
set InstallPath="\\SomeServer6
goto Install
:DefaultInstall
@Echo on
::DO: Stuff
set InstallPath="\\SomeServer0
goto Install
:Install
rem Insert install code here. Use the variable "%InstallPath%" (without quotes) to call the local office path to \\SomeServerX\SomeFolder
rem Example for an installation of Whatever.MSI located in \\SomeServerX\SomeFolder:
rem msiexec /package %InstallPath%\SomeFolder\W
REM Insert install code below:
goto eof
:eof
Set Prompt=$P$G
echo Done!
Commented:
http://scripts.dragon-it.co.uk/links/batch-get-tcpip-subnet
Open in new window