#176844 - 2007-06-08 07:43 PM
Manage Wireless Laptops
|
dgraham
Fresh Scripter
Registered: 2006-04-11
Posts: 39
Loc: Santa Fe, New Mexico
|
You guys have helped me several times before, and I was hoping that someone out there might have a suggestion on how to do what I need to accomplish. Basically I need to have the Windows XP laptops I maintain run a script when they connect to the 802.11 network. Unfortunately I cannot be sure the end user will bring the laptop into the office, and run a logon script because they usually never log off the laptop. They just close the lid, which puts it into suspend mode. When they come into the office, they wake up the computer, and unlock it, but they do not do a true logon so no logon script runs. I thought about just using a loop that pings a network address and if it gets a response, then assume it is connected and call another script located on a network server, but for technical reasons I cannot do this. (The laptops also have sattelite access which is horrendously expensive, and every ping has an actual monetary cost. Besides, the ping would always be succesful.) So I imagine something running locally to the laptop that can query the OS and determine that 802.11 is connected and then call the script. I was thinking of using WMI to somehow determine the state of the Wireless connection, but I don't know if this would be the best approach. Any ideas?
|
|
Top
|
|
|
|
#176850 - 2007-06-08 11:21 PM
Re: Manage Wireless Laptops
[Re: Mart]
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
this is one that I'm working on... it needs some massaging, but I haven't had time to get back to it.
break on
$Query = "SELECT TargetInstance.Name FROM __InstanceOperationEvent WITHIN 4 WHERE TargetInstance ISA 'Win32_NetworkAdapterConfiguration' and targetInstance.IPEnabled = true"
$objEvents = GetObject("winmgmts:\\.\root\cimv2").ExecNotificationQuery($query)
While 1
? 'waiting'
$objConnectEvent = $objEvents.nextevent
? 'event'
sleep 5
$aIPAddress = $objConnectEvent.TargetInstance.IPAddress
For Each $sAddress in $aIPAddress
? $sAddress
sleep 5
? 'pinging'
$Res = wmiPing('server',5000)
If not @error
? $res
$question=messagebox("Do you want to Start the Logon Script?","Network Detected",36)
if $question = 6
shell 'cmd /c start kix32 \\server\netlogon\kixtart.kix'
endif
endif
Next
loop
Function wmiPing($Address,Optional $Timeout,Optional $BlockSize)
Dim $Query,$oWMI,$oItem,$cItems
$Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $Address + "'"
If $Timeout
$Query = $Query + " And TimeOut=" + $Timeout
EndIf
If $BlockSize
$Query = $Query + " And BufferSize=" + $BlockSize
EndIf
$oWMI = GetObject("winmgmts:root\cimv2")
$cItems = $oWMI.ExecQuery($Query)
For Each $oItem In $cItems
If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
Exit 1
Else
$wmiPing = $oItem.ResponseTime
EndIf
Next
EndFunction
|
|
Top
|
|
|
|
#176960 - 2007-06-13 07:04 PM
Re: Manage Wireless Laptops
[Re: Mart]
|
dgraham
Fresh Scripter
Registered: 2006-04-11
Posts: 39
Loc: Santa Fe, New Mexico
|
Thanks for yor replies. I have been playing with the script Mart posted and it seems to work for what I need. Here is what I have so far. I am a little worried about having the script running all the time on the laptops. I thought about bundling it as an EXE with AdminScriptEditor and starting it as a service, but it seems that it wont have access to the HKCU when it runs under alternative credentials so I figure I will just put it in the startup folder and run it hidden. I wanted to run it as a service so I could set it to restart in the event of a failure. Not sure how to do that otherwise. Also, the way I've written it, it can only be stopped by using task manager. I was hoping someone out there would have some suggestions for polishing it up a little. Thanks
$ = SetConsole ("Hide")
Break on
If KeyExist ("HKLM\Software\MyMobile")
;Do nothing
Else
$ = WriteValue ("HKLM\Software\MyMobile","LastRunDate","",REG_SZ)
EndIf
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_NetworkAdapter")
:StartAgain
For Each $wmiObj in $wmiColl
$test = $wmiObj.name
If InStr($test, "Wireless")
;NetConnectionStatus returns 0 for not connected and 2 for connected.
If $wmiObj.NetConnectionStatus = 2
If Exist ("\\SERVER\Folder\Mobile.bat")
$LastRunDate = ReadValue ("HKLM\Software\MyMobile","LastRunDate")
If $LastRunDate = @DATE
; Do nothing
Else
Shell "%COMSPEC% /c \\Server\Folder\Mobile.bat"
$ = WriteValue ("HKLM\Software\MyMobile","LastRunDate","@DATE",REG_SZ)
EndIf
EndIf
EndIf
Sleep 60
EndIf
Next
Goto StartAgain
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1376 anonymous users online.
|
|
|