Xenobiologist Posted September 11, 2008 Share Posted September 11, 2008 (edited) Hi, anybody a good func for detecting WLAN status? All I want to know is whether I'm connected via WLAN. Using WMI is not that easy in this point. Regex on ipconfig /all is difficult, because it is language dependent. Wlan on? Wlan off? Wlan connected? Wlan on but not connected? (no IP) Thanks! Mega P.S.: Yes, I did a search and yes I did find a lot of good code, but not I needed. Here is what I tried the last 20 min I want to automate the process of switching on WLAN and connect via VPN. If LAN is connected, WLAN should be switched off, if its on and if there is a Process vpngui.exe then it should be closed. expandcollapse popupGlobal Const $NETWORK_ALIVE_LAN = 0x1 ;net card connection Global Const $NETWORK_ALIVE_WAN = 0x2 ;RAS connection Global Const $NETWORK_ALIVE_AOL = 0x4 ;AOL Global $VPN_exe = 'vpngui.exe' Global $VPN_path = 'c:\Programme\Cisco Systems\VPN Client\vpngui.exe' Global $WLAN_exe = 'TpFnF5.exe' Global $WLAN_path = 'c:\Programme\Lenovo\HOTKEY\' Global $wifiAdapter = 'Intel® Wireless WiFI Link 4965AGN' $connect = _GetNetworkConnect() If @extended Then _closeAllButLAN() Exit (0) EndIf ShellExecute($WLAN_exe, '/WLON', $WLAN_path, 'open') Do Sleep(100) ConsoleWrite(_signal() & @CRLF) Until StringLen(_signal()) > 1 If ProcessExists($VPN_exe) Then ProcessWaitClose($VPN_exe, 2000) ShellExecute($VPN_path, '-sc') Else Sleep(4000) ShellExecute($VPN_path, '-sc') EndIf Func _closeAllButLAN() If ProcessExists($VPN_exe) Then ProcessClose($VPN_exe) ShellExecute($WLAN_exe, '/WLOFF', $WLAN_path, 'open') EndFunc ;==>_closeAllButLAN Func _signal() $signal = "" $strComputer = "." $objWMI = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi") $colItems = $objWMI.InstancesOf("MSNdis_80211_ReceivedSignalStrength WHERE InstanceName ='" & $wifiAdapter & "'") For $objItem In $colItems $intStrength = $objItem.NDIS80211ReceivedSignalStrength If $intStrength > -57 Then $signal = "Excellent" ElseIf $intStrength > -68 Then $signal = "Very Good" ElseIf $intStrength > -72 Then $signal = "Good" ElseIf $intStrength > -80 Then $signal = "Low" ElseIf $intStrength > -90 Then $signal = "Very Low" EndIf Next If StringLen($signal) = 0 Then Return 0 Return $signal EndFunc ;==>_signal Func _GetNetworkConnect() ; @extended set by function on return, use as boolean 'IsConnected' Local $aResult, $sResult = "", $iData, $iError = 0 $aResult = DllCall("sensapi.dll", "int", "IsNetworkAlive", "int*", 0) $iError = @error If @error Or IsArray($aResult) = 0 Then Return SetError($iError, 0, "") $iData = $aResult[1] If BitAND($iData, $NETWORK_ALIVE_LAN) Then $sResult &= "LAN connected" & @LF If BitAND($iData, $NETWORK_ALIVE_WAN) Then $sResult &= "WAN connected" & @LF If BitAND($iData, $NETWORK_ALIVE_AOL) Then $sResult &= "AOL connected" & @LF Return SetError($iError, $aResult[0], $sResult) EndFunc ;==>_GetNetworkConnect Edited September 12, 2008 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
trancexx Posted September 11, 2008 Share Posted September 11, 2008 Hi, anybody a good func for detecting WLAN status? All I want to know is whether I'm connected via WLAN. Using WMI is not that easy in this point. Regex on ipconfig /all is difficult, because it is language dependent. Wlan on? Wlan off? Wlan connected? Wlan on but not connected? (no IP) Thanks! Mega Couldn't you check what is connected and then see it it's WLAN? MsgBox(0, "WLAN CONNECTED", Check_WLAN_Status()) Func Check_WLAN_Status() Local $caption, $WLAN_CONNECTED Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2") For $objNetCard In $NetCards $caption = $objNetCard.Caption ; Name; Description; ProductName Next If StringInStr($caption, 'WLAN') <> 0 Then $WLAN_CONNECTED = 1 Else $WLAN_CONNECTED = 0 EndIf Return $WLAN_CONNECTED EndFunc ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 11, 2008 Author Share Posted September 11, 2008 Hi, thanks for reply, but that doesn't work either. I checked the answer and changed it to because my adapter has only Wireless in its name [00000018] Intel® 82566MM Gigabit Network Connection [00000020] Intel® Wireless WiFi Link 4965AGN [00000026] 1394-Netzwerkadapter [00000027] VMware Virtual Ethernet Adapter for VMnet1 [00000028] VMware Virtual Ethernet Adapter for VMnet8 MsgBox(0, "WLAN CONNECTED", Check_WLAN_Status()) Func Check_WLAN_Status() Local $caption, $WLAN_CONNECTED Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2") For $objNetCard In $NetCards $caption = $objNetCard.Caption ; Name; Description; ProductName ConsoleWrite($caption & @CRLF) If StringInStr($caption, 'Wireless') <> 0 Then $WLAN_CONNECTED = 1 Return 1 Else $WLAN_CONNECTED = 0 EndIf Next Return $WLAN_CONNECTED EndFunc ;==>Check_WLAN_Status So, this works but it also depends on a string which can be different from computer to computer and that is bad. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
trancexx Posted September 11, 2008 Share Posted September 11, 2008 Maybe like this: MsgBox(0, "WLAN CONNECTED", Check_WLAN_Status()) Func Check_WLAN_Status() Local $name Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2") For $objNetCard In $NetCards $name = $objNetCard.Name Next ;ConsoleWrite($name & @CRLF) Local $instance_name, $WLAN_CONNECTED = 0 Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\wmi") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM MSNdis_80211_Configuration") For $objItem In $colItems $instance_name = $objItem.InstanceName ;ConsoleWrite($instance_name & @CRLF) If StringInStr($instance_name, $name) <> 0 Then $WLAN_CONNECTED = 1 EndIf Next Return $WLAN_CONNECTED EndFunc ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 12, 2008 Author Share Posted September 12, 2008 Hi, thanks for that, but it is one and the same thing. You also need to check for the sepecific string like Wireless or WiFi and so on. This behaviour is improper for a universal udf. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Community On Patrol Posted September 12, 2008 Share Posted September 12, 2008 Hi Xenobiologist, Please create descriptive topics. Using one word topics makes it really difficult to use the search feature, and those that could probably answer your question will probably not even read your thread. Doing it enough could cause your posting privileges to be taken away all together, and we don't want that . Thanks. Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 12, 2008 Author Share Posted September 12, 2008 Hi, ??? the keyword is WLAN and if you do a search on that, you will find this topic!!! Nevertheless I could try to describe the problem in detail. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
trancexx Posted September 12, 2008 Share Posted September 12, 2008 (edited) Hi,thanks for that, but it is one and the same thing. You also need to check for the sepecific string like Wireless or WiFi and so on.This behaviour is improper for a universal udf.MegaSure, no problem. But to answer that... Respectively:-no it's not-no you don't-no it's notWhy don't you try it? Edited September 12, 2008 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 12, 2008 Author Share Posted September 12, 2008 Sure, no problem. But to answer that... Respectively: -no it's not -no you don't -no it's not Why don't you try it? Hi, hadn't got the time to look at your code closer. I only did a run and it didn't work. I changed it to this and now I think I'm happy with result although it is very slow. ConsoleWrite("+> -------------------------------------------" & @CRLF) ConsoleWrite("WLAN CONNECTED " & Check_WLAN_Status() & @CRLF) ConsoleWrite("+> -------------------------------------------" & @CRLF) Opt('MustDeclareVars', 1) Func Check_WLAN_Status() Local $instance_name Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\wmi") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM MSNdis_80211_Configuration") For $objItem In $colItems $instance_name = $objItem.InstanceName ; get name of WLAN-apdater Next Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2") For $objNetCard In $NetCards If StringInStr($instance_name, $objNetCard.Name) <> 0 Then Return 1 Next Return 0 EndFunc ;==>Check_WLAN_Status Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
trancexx Posted September 12, 2008 Share Posted September 12, 2008 (edited) Slowness is "product" of loops used to access data returned by ExecQuery method called by WMI and by method it self, but that's the only way. That code that you provided looks logical, and was what I started with when you said that there is no 'WLAN' in your adapter's name. But I dropped it because... well, it is not good. You are using Local $instance_name Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\wmi") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM MSNdis_80211_Configuration") For $objItem In $colItems $instance_name = $objItem.InstanceName; get name of WLAN-apdater Next to get the name of WLAN apdater. But what happens when there are more then one of them? You will only get the name of the last one and that one may not be connected. What you need to do is check each one by doing this (for every one!):Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2") For $objNetCard In $NetCards If StringInStr($instance_name, $objNetCard.Name) <> 0 Then Return 1 Next Or you could gather data in some array and check every element afterwards. Either way, new loops are created and more time is (would be) lost. The code that I suggested is doing it backwards. First checks what is connected and then checks if that exists in list of WLAN apdaters. If it does function will return 1. Why this method does not work for you is a different issue, but can be resolved , I'm sure. Edited September 12, 2008 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 12, 2008 Author Share Posted September 12, 2008 Hi, yes and yes and yes Already thought of doing like this ConsoleWrite("+> -------------------------------------------" & @CRLF) ConsoleWrite("WLAN CONNECTED " & Check_WLAN_Status() & @CRLF) ConsoleWrite("+> -------------------------------------------" & @CRLF) Opt('MustDeclareVars', 1) Func Check_WLAN_Status() Local $instance_name, $WLAN_adapter_A[1], $i = 0 Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\wmi") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM MSNdis_80211_Configuration") For $objItem In $colItems $WLAN_adapter_A[$i] = $objItem.InstanceName ; get name of WLAN-apdater $i += 1 ReDim $WLAN_adapter_A[$i + 1] Next Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2") For $i = 0 To UBound($WLAN_adapter_A) - 1 For $objNetCard In $NetCards If StringInStr($WLAN_adapter_A[$i], $objNetCard.Name) <> 0 Then Return 1 Next Next Return 0 EndFunc ;==>Check_WLAN_Status But who has got more than 1 WLAN interface ? Only those who want to hack the encryption of a WLAN. >_< Thanks anyway! Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
weaponx Posted September 12, 2008 Share Posted September 12, 2008 What operating system is this on? Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 12, 2008 Author Share Posted September 12, 2008 What operating system is this on?Hi,I tried it on WIN XP PROF. SP2Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
trancexx Posted September 12, 2008 Share Posted September 12, 2008 Ubuntu no just kidding... XP Professional SP3I suppose there is problem with Vista? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now