Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script to run only on a given subnet

Reply
 
Old 02-01-2009   #1 (permalink)
Glenn


 
 

Script to run only on a given subnet

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.



My System SpecsSystem Spec
Old 02-02-2009   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Script to run only on a given subnet


"Glenn" <nospam@xxxxxx> wrote in message
news:uNIoyUOhJHA.5244@xxxxxx
Quote:

> 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


My System SpecsSystem Spec
Old 02-08-2009   #3 (permalink)
Glenn


 
 

Re: Script to run only on a given subnet

I am trying the simple solution, but it doesn't work.

Here's exactly what I am typing. (my ip address is 172.16.31.155)

ipconfig | find /i "IP_Address" | find /i "172.16.31" && "bginfo
c:\bginfo\mysetup.bgi /timer:0"

But it doesn't run.

If i type the bginfo c:\bginfo\mysetup.bgi /timer:0 on a line by itself it
works fine.

Thanks for any direction you can provide me.


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:uJA$wGThJHA.3812@xxxxxx
Quote:

>
> "Glenn" <nospam@xxxxxx> wrote in message
> news:uNIoyUOhJHA.5244@xxxxxx
Quote:

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

My System SpecsSystem Spec
Old 02-08-2009   #4 (permalink)
Glenn


 
 

Re: Script to run only on a given subnet

disregard I found the error. no _ between IP & Address.
"Glenn" <nospam@xxxxxx> wrote in message
news:ey$Yw2hiJHA.3708@xxxxxx
Quote:

>I am trying the simple solution, but it doesn't work.
>
> Here's exactly what I am typing. (my ip address is 172.16.31.155)
>
> ipconfig | find /i "IP_Address" | find /i "172.16.31" && "bginfo
> c:\bginfo\mysetup.bgi /timer:0"
>
> But it doesn't run.
>
> If i type the bginfo c:\bginfo\mysetup.bgi /timer:0 on a line by itself it
> works fine.
>
> Thanks for any direction you can provide me.
>
>
> "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
> news:uJA$wGThJHA.3812@xxxxxx
Quote:

>>
>> "Glenn" <nospam@xxxxxx> wrote in message
>> news:uNIoyUOhJHA.5244@xxxxxx
Quote:

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

My System SpecsSystem Spec
Old 02-09-2009   #5 (permalink)
Al Dunbar


 
 

Re: Script to run only on a given subnet


"Glenn" <nospam@xxxxxx> wrote in message
news:%23AlIIamiJHA.1172@xxxxxx
Quote:

> disregard I found the error. no _ between IP & Address.
Did you also remove the double-quotes from the bginfo command?

/Al
Quote:

> "Glenn" <nospam@xxxxxx> wrote in message
> news:ey$Yw2hiJHA.3708@xxxxxx
Quote:

>>I am trying the simple solution, but it doesn't work.
>>
>> Here's exactly what I am typing. (my ip address is 172.16.31.155)
>>
>> ipconfig | find /i "IP_Address" | find /i "172.16.31" && "bginfo
>> c:\bginfo\mysetup.bgi /timer:0"
>>
>> But it doesn't run.
>>
>> If i type the bginfo c:\bginfo\mysetup.bgi /timer:0 on a line by itself
>> it works fine.
>>
>> Thanks for any direction you can provide me.
>>
>>
>> "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
>> news:uJA$wGThJHA.3812@xxxxxx
Quote:

>>>
>>> "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
>>>
>>>
>>
>>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Windows browsing in an IP subnet with no DC .NET General
Vista sharing and subnet Vista networking & sharing
IPSec: IP-Rule with subnet Vista networking & sharing
Create a subnet in AD PowerShell
subnet problem Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46