Page 1 of 1 1
Topic Options
#176844 - 2007-06-08 07:43 PM Manage Wireless Laptops
dgraham Offline
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
#176845 - 2007-06-08 07:46 PM Re: Manage Wireless Laptops [Re: dgraham]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Or inverselly monitor the 802.11 network for users attaching (query your dhcp server for example) and when you see a new attachment run an admin script against simulating the logon script.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#176849 - 2007-06-08 09:04 PM Re: Manage Wireless Laptops [Re: Gargoyle]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yeeha, my first WMI script \:o
It is not bullet proof because it relies on the name of the network connection having wireless in it.

 Code:
Break on

$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_NetworkAdapter")

For Each $wmiObj in $wmiColl
	If InStr($wmiObj.name, "Wireless")
		;NetConnectionStatus returns 0 for not connected and 2 for connected.
		If $wmiObj.NetConnectionStatus = "2"
			;do all kinds of stuff.
			;maybe ping a server in the on the network you want it to connect to
			;and if ping is successful run the login script
			;because users might connect to a wifi network at home.
		Else
			;wifi is not connected.
		EndIf
	Else
		;not a wifi connection.
	EndIf
Next
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#176850 - 2007-06-08 11:21 PM Re: Manage Wireless Laptops [Re: Mart]
Radimus Moderator Offline
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.

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



_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#176960 - 2007-06-13 07:04 PM Re: Manage Wireless Laptops [Re: Mart]
dgraham Offline
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
 Code:
 
$ = 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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.056 seconds in which 0.028 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org