Quantcast
Channel: 2BrightSparks
Viewing all articles
Browse latest Browse all 9303

Re: Run profile conditional on network in use

$
0
0
For those people who want a script to do this, IsHomeNetwork.vbs does some odd things, the following (based on IsHomeNetwork) may be a bit more useful:

' For Syncback, "Programs - Before" script to check if we're in the
' home network.  This needs to be set for each profile (not for
' overall group profiles).
'
' Checks the DHCP server/default gateway address.

InHomeNetwork = 1   ' Return value to stop profile running

' Required DHCP server/gateway address to run

strRequiredDHCP = ""
strRequiredGateway = "192.168.10.1"

' Check for matching DHCP server and/or default gateway

Set objWMI = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMI.ExecQuery( "SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE" )

For Each objItem In colItems
'   WScript.Echo "DHCP: " & objItem.DHCPServer
   If Not IsNull( strRequiredDHCP ) And strRequiredDHCP = objItem.DHCPServer Then
      InHomeNetwork = 0   ' Return value to let profile run
      Exit For
   End If
   If Not IsNull( strRequiredGateway ) Then
      For i = LBound( objItem.DefaultIPGateway ) To UBound( objItem.DefaultIPGateway )
'         WScript.Echo "Gateway: " & objItem.DefaultIPGateway( i )
         If strRequiredGateway = objItem.DefaultIPGateway( i ) Then    
            InHomeNetwork = 0   ' Return value to let profile run
            Exit For
         End If
      Next
   End If
Next

Set objWMI = Nothing
Set colItems = Nothing

' Tell the caller what to do

Wscript.Quit( InHomeNetwork )


It'd still be nice to have this facility built into SyncBack though (see my sample code above), since having a command-line window flash up for every profile (I have several, that get run hourly) gets quite annoying.

Viewing all articles
Browse latest Browse all 9303

Trending Articles