Startup Script or Batch file

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
OttawayaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

johnb6767Commented:
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

0
Ste206Commented:
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

0
PberSolutions ArchitectCommented:
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

0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Ste206Commented:
sorry I forgot to add the start for applications...

Here's a working code I've added pauses in it for now so you can test it better, just remove them once you have it working.
@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
start app1.exe
start app2.exe
start app3.exe
@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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OttawayaAuthor 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
0
Ste206Commented:
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 :)
0
OttawayaAuthor Commented:
perfect...thanks all... got it working
0
Ste206Commented:
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"
0
PberSolutions ArchitectCommented:
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.
0
OttawayaAuthor Commented:
ok thought it was working but when i try to launch oultook it just pops open a command prompt.

Any thoughts?.
0
OttawayaAuthor 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...
0
PberSolutions ArchitectCommented:
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
 
0
Ste206Commented:
start "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"  /recycle
0
Ste206Commented:
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.
0
OttawayaAuthor 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
0
johnb6767Commented:
I honestly dont see the difference, besides a tad more verbosity on the accepted script, versus the first posting I made....
 
0
Ste206Commented:
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.
0
johnb6767Commented:
"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....
0
PberSolutions ArchitectCommented:
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.  
0
Ste206Commented:
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.
0
johnb6767Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.