We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Startup Script or Batch file

Ottawaya
Ottawaya asked
on
Medium Priority
518 Views
Last Modified: 2012-05-07
Hi,

I am looking for a way to check the current IP of a computer.If the IP is from our subnet i want applications to launch at startup ,If subnet is incorrect the applications should not start.. Does anyone know of a routine to accomplish this..(Windows XP)

For laptop startups out of office..

TIA
Ron
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011

Commented:
Kinda dirty, but works..... Change your subnet in it though.... And yourapp.exe
@echo off
ipconfig /all | find /i "IP Address. . . . . . . . . . . . : 10.72.30"
if not %errorlevel%==0 goto exit
start yourapp.exe
goto exit
 
:exit
exit

Open in new window

Commented:
There you go :)
@echo off
ipconfig /all | find /c /i "255.255.0.0"
REM: ----------------- SET YOUR OWN SUBNET ^^
if not %errorlevel%==0 goto exit
cls
@echo:Loading Applications..
REM: Your applications here
@echo:Closing...
pause
REM: ----------------- REMOVE THE PAUSE ^^
exit
:exit
cls
@echo:No Applications To Load.
@echo:Closing...
pause
REM: ----------------- REMOVE THE PAUSE ^^
exit

Open in new window

PberSolutions Architect
CERTIFIED EXPERT

Commented:
Or VBScript:
set ws =CreateObject("MSWinsock.Winsock") 
ipaddress = ws.localip
WScript.Echo ipaddress
If instr(1,ipaddress,"192.168.0.") Then 'adjust to your subnets as needed
'do something
	RunProgram("notepad.exe") 'change to your program
End If
If instr(1,ipaddress,"192.168.5.") Then 'adjust to your subnets as needed
'do something Else
	RunProgram("cmd.exe") 'change to your program
End If
 
Sub RunProgram(strProgram) 
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run strProgram
End Sub

Open in new window

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for all of these... i need to check whether the PC is in our subnet... what do i enter for subnet.

ipconfig /all | find /c /i "10.0.0.0/255.255.0.0"

all clients are dhcp how do i determine the ip is in the subnet.

Thanks

Commented:
ipconfig /all | find /c /i "255.255.0.0"

that's usualy the subnet 10.0.0.0 would be the IP's starting range :)

Author

Commented:
perfect...thanks all... got it working

Commented:
or if you want to make 100% sure its only the SUBNET the find will see use

ipconfig /all | find /c /i "Subnet Mask . . . . . . . . . . . : 255.255.0.0"
PberSolutions Architect
CERTIFIED EXPERT

Commented:
How is this finding the subnet that the client is in?  It looks to me it's just confirming that the client is using a subnet mask of a B-Class subnet.

Author

Commented:
ok thought it was working but when i try to launch oultook it just pops open a command prompt.

Any thoughts?.

Author

Commented:
start "C:\Program Files\Microsoft Office\Office12\outlook.exe"

this does not work.. it starts CMD..

but

start c:\windows\system32\notepad.exe   runs fine...
PberSolutions Architect
CERTIFIED EXPERT

Commented:
You may need to drop the start command or use 8.3 naming conventions.
 
just use this in the batch:
"C:\Program Files\Microsoft Office\Office12\outlook.exe"
or use 8.3:
start  "c:\progra~1\micros~3\office12\outlook.exe"
careful as there are many microsoft folders so it may be ~7
 

Commented:
start "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"  /recycle

Commented:
By adding /recycle to the end it checks if outlook.exe is already running, if it isnt it loads it.. because its checking for the Windows running version of outlook it forces outlook to run as what we would classify as 'normal'

The reason outlook runs as a cmd window is because outlook CAN be used as a cmd emailer also and because you was calling it from a cmd window it presumed you wanted it loading that same way..

Use the above command and it will work around it for you.

Hope this helps.

Author

Commented:
ok what i did and its working fine now is add a "title"

start "outlook" "C:\Program Files\Microsoft Office\Office12\outlook.exe"

this seems to be what i need.. I have tested on users Laptop and all apps start fine now..

Thanks for all the help..
Ron
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011

Commented:
I honestly dont see the difference, besides a tad more verbosity on the accepted script, versus the first posting I made....
 

Commented:
ipconfig /all | find /i "IP Address. . . . . . . . . . . . : 10.72.30"
That wont find a Subnet Mask due to it searching for the line starting with "IP Address"

It would need to be
ipconfig /all | find /c /i "Subnet Mask . . . . . . . . . . . : x.x.x.x"
OR
ipconfig /all | find /c /i "x.x.x.x"

^ Replace x.x.x.x with the Subnet.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011

Commented:
"f the IP is from our subnet"
Asker didnt ask for a subnet mask. Asked for an IP on teh subnet, which are two TOTALLY different things.....
If he has 10 /24 subnets, they are all going to be 255.255.255.0, but most likely all different subnets.....
Subnet 10.72.30.x/24 would always contain "IP Address. . . . . . . . . . . . : 10.72.30" in the IPConfig. And ONLY that subnet....
PberSolutions Architect
CERTIFIED EXPERT

Commented:
I would have to agree with John6767, I made the same comment earlier.  This isn't finding the subnet at all, just confirming a subnet mask.  

Commented:
Both ways work though, and I went from him asking 'If subnet is incorrect the applications should not start..' so I presumed he would want it searching the Subnet and not the IP, although initially he quesetioned about the IP Address the question then moved onto Subnet Masks and Starting Apps so thats why I chose the route I did..

We're all individuals and have our own ways of working and reading questions, at the end of the day its the 'questioner' that gets the final say as to whom answered their question how they wanted.

Sorry if I offended anyone as that isn't what I intended to do, I was simply trying to help someone by answering a question asked.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011

Commented:
Not once did the asker ask about finding a Subnet Mask. Search the page....
And I dont think it is possible to find the proper subnet by using 255.255.0.0 (unless you have custom subnetting, and each custom subnet is unique - EG 255.255.255.128, 255.255.252.0 etc....), so the answer is just wrong. If you search for 192.168.1, then you will determine if thats the subnet you want, based on the IP minus the node number.
"at the end of the day its the 'questioner' that gets the final say as to whom answered their question how they wanted."
To an extent yes, but we as participants here at the site have a responsibility to make sure that questions that get stored in teh database are 100% accurate. If an asker accepts an answer, it can be overturned if it is not correct, technically. Thats what our premium users come to this site... Accurate and swift answers...
Notice I am not questioning PBer's script, as it was technically correct.
I just want the Original asker to understand  whats going on here with this thread.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.