Solved

Startup Script or Batch file

Posted on 2009-07-09
21
501 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
  • 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
 
LVL 2

Accepted Solution

by:
Ste206 earned 500 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now