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