Windows Vista Forums

Script to run only on a given subnet

  1. #1


    Glenn Guest

    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

  2. #2


    Pegasus \(MVP\) Guest

    Re: Script to run only on a given subnet


    "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

  3. #3


    Glenn Guest

    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

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

  4. #4


    Glenn Guest

    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

    >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

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

  5. #5


    Al Dunbar Guest

    Re: Script to run only on a given subnet


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

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

    /Al

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

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

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

Script to run only on a given subnet

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual PC on a different subnet? Virtual Server 3 19 Feb 2010
If connected to subnet xxx.xxx.xxx.xxx then.... Jake VB Script 0 15 Feb 2010
two domains, one subnet Gorge Server General 1 18 Aug 2009
Create a subnet in AD BZP PowerShell 15 15 Sep 2007
subnet problem frro Vista networking & sharing 1 14 Mar 2007