Networking Forums

Networking Forums > Computer Networking > Windows Networking > Triggering script when network interface comes up

Reply
Thread Tools Display Modes

Triggering script when network interface comes up

 
 
Kenneth Porter
Guest
Posts: n/a

 
      04-19-2007, 08:25 PM
I need to map drives once a wireless NIC finishes establishing a
connection. Is there some way to tie a script (either a simple batch file
or WSH or some other program) to this event?

This is on a workstation but I figure the mechanism should be the same
across the whole Windows product line and server admins would be more
familiar with how to do this.

Some Googling suggested using a login script for this, but the interface
doesn't come up until well after the login, so a script run at login will
be talking to a "dead" interface and will fail.
 
Reply With Quote
 
 
 
 
Jeremy
Guest
Posts: n/a

 
      04-20-2007, 10:54 AM
Hi,

I think this will do the job. In my testing, the script detects the network
as connected a couple of seconds prior to the establishment of a network
address, so it might be worth putting in another 5 second wait after the
network is connected before trying to map any drives. Here it is:

'On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const NOTCONNECTED = 7
Const CONNECTED = 2

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

'Set the initial condition
strLinkStatus = "Unknown"

'The longest time the script will wait for in seconds
intDropDeadTime = 60
intRunTime = 0

While strLinkStatus <> "Connected" AND intRunTime < intDropDeadTime
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter
WHERE NetConnectionID = 'Wireless Network Connection'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If objItem.NetConnectionStatus = CONNECTED Then
strLinkStatus = "Connected"
WScript.Echo "Link detected, do something."
Else
WScript.Echo "Link not detected, waiting for 5 seconds"
WScript.Sleep 5000
intRunTime = intRunTime + 5
WScript.Echo "I've been running for " & intRunTime & " seconds." & vbCrLf
End If
Next
Wend

Cheers,
Jeremy.

"Kenneth Porter" wrote:

> I need to map drives once a wireless NIC finishes establishing a
> connection. Is there some way to tie a script (either a simple batch file
> or WSH or some other program) to this event?
>
> This is on a workstation but I figure the mechanism should be the same
> across the whole Windows product line and server admins would be more
> familiar with how to do this.
>
> Some Googling suggested using a login script for this, but the interface
> doesn't come up until well after the login, so a script run at login will
> be talking to a "dead" interface and will fail.
>

 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does port triggering work? mike Network Routers 12 02-28-2010 02:50 AM
Execute a script when a network-interface come up? Lasse Madsen Linux Networking 19 12-09-2005 04:11 PM
I am in need of a netsh script that will disable the "Local Area Connection" interface then re-enable that same interface. Spin Windows Networking 3 11-03-2005 12:58 AM
UPNP vs Port Triggering TC Broadband Hardware 1 01-12-2004 10:32 PM
What is really port triggering? Rim Wireless Internet 2 10-06-2003 11:13 PM



1 2 3 4 5 6 7 8 9 10 11