Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Startup Script or Batch file

Posted on 2009-07-09
21
Medium Priority
?
508 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
0
Comment
Question by:Ottawaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
  • +1
21 Comments
 
LVL 66

Expert Comment

by:johnb6767
ID: 24813871
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
 
LVL 2

Expert Comment

by:Ste206
ID: 24814028
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
 
LVL 26

Expert Comment

by:Pber
ID: 24814048
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Accepted Solution

by:
Ste206 earned 2000 total points
ID: 24814051
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
 

Author Comment

by:Ottawaya
ID: 24814124
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
 
LVL 2

Expert Comment

by:Ste206
ID: 24814166
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
 

Author Comment

by:Ottawaya
ID: 24814171
perfect...thanks all... got it working
0
 
LVL 2

Expert Comment

by:Ste206
ID: 24814181
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
 
LVL 26

Expert Comment

by:Pber
ID: 24814240
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
 

Author Comment

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

Any thoughts?.
0
 

Author Comment

by:Ottawaya
ID: 24814340
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
 
LVL 26

Expert Comment

by:Pber
ID: 24814545
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
 
LVL 2

Expert Comment

by:Ste206
ID: 24814561
start "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"  /recycle
0
 
LVL 2

Expert Comment

by:Ste206
ID: 24814605
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
 

Author Comment

by:Ottawaya
ID: 24814757
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
 
LVL 66

Expert Comment

by:johnb6767
ID: 24831510
I honestly dont see the difference, besides a tad more verbosity on the accepted script, versus the first posting I made....
 
0
 
LVL 2

Expert Comment

by:Ste206
ID: 24837841
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
 
LVL 66

Expert Comment

by:johnb6767
ID: 24846396
"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
 
LVL 26

Expert Comment

by:Pber
ID: 24849460
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
 
LVL 2

Expert Comment

by:Ste206
ID: 24857533
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
 
LVL 66

Expert Comment

by:johnb6767
ID: 24866648
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

609 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