Ottawaya
asked on
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
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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 :)
that's usualy the subnet 10.0.0.0 would be the IP's starting range :)
ASKER
perfect...thanks all... got it working
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"
ipconfig /all | find /c /i "Subnet Mask . . . . . . . . . . . : 255.255.0.0"
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.
ASKER
ok thought it was working but when i try to launch oultook it just pops open a command prompt.
Any thoughts?.
Any thoughts?.
ASKER
start "C:\Program Files\Microsoft Office\Office12\outlook.ex e"
this does not work.. it starts CMD..
but
start c:\windows\system32\notepa d.exe runs fine...
this does not work.. it starts CMD..
but
start c:\windows\system32\notepa
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.ex e"
or use 8.3:
start "c:\progra~1\micros~3\offi ce12\outlo ok.exe"
careful as there are many microsoft folders so it may be ~7
just use this in the batch:
"C:\Program Files\Microsoft Office\Office12\outlook.ex
or use 8.3:
start "c:\progra~1\micros~3\offi
careful as there are many microsoft folders so it may be ~7
start "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EX E" /recycle
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.
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.
ASKER
ok what i did and its working fine now is add a "title"
start "outlook" "C:\Program Files\Microsoft Office\Office12\outlook.ex e"
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
start "outlook" "C:\Program Files\Microsoft Office\Office12\outlook.ex
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
I honestly dont see the difference, besides a tad more verbosity on the accepted script, versus the first posting I made....
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.
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.
"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....
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....
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.
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.
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.
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.
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.
Open in new window