"Glenn" <nospam@xxxxxx> wrote in message
news:uNIoyUOhJHA.5244@xxxxxx
> Is it possible to write a startup script that will run a program such as
> BGinfo only if the computer is on one of a list of specified subnets?
>
> For instance, I want my laptops to run this program only if they are
> connected to my network internally.
>
> When they try to run them from the outside, they get an error message that
> the SQL server can't be contacted, which of course it can't because they
> aren't on the network.
>
> Thanks. The simplest solution is to insert this line into your startup batch file.
It assumes that "192.168.1" is your internal subnet address.
ipconfig | find /i "IP_Address" | find /i "192.168.1" && "c:\Program
Files\My Folder\My Prog.exe"
If you prefer a chatty solution then you can built it on this VB Script:
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set cNicConfigs = oWMIService.ExecQuery("SELECT * FROM " _
& "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each oNICConfig In cNicConfigs
For Each sIPAddress In oNICConfig.IPAddress
WScript.Echo "Subnet = " & Left(sIPAddress, InStrRev(sIPAddress, ".")-1)
Next
Next