Jump to content

wifi question


Recommended Posts

I'm looking for something pretty simple. Has anyone made anything to simply turn on and off the wifi in the laptop? I saw some scripts/functions for entire wifi functions minus that simple thing...from what I saw at least. Just need to simply turn it off and on. Any help?

Link to comment
Share on other sites

I had this code in my script at one point. It may or may not work for you, I wrote it quick and dirty to work specifically on my PC, although it might work on any PC with Windows Mobility Center. It is a toggle, BTW.

If Not WinExists("Windows Mobility Center") Then
    Run("mblctr.exe")
    WinWaitActive("Windows Mobility Center")
EndIf
ControlClick("Windows Mobility Center", "", "Button2")
WinClose("Windows Mobility Center")

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

I'm looking for something pretty simple. Has anyone made anything to simply turn on and off the wifi in the laptop?

Define "Turn Off".

You can shut off power to it from your BIOS usually, that's the most drastic solution.

You can also disable the device via WMI (http://msdn.microsoft.com/en-us/library/Aa394595) or other means.

Finally, you can disconnect a card from the network using the _Wlan_Disconnect() function in the UDF that darkjohn linked you.

Link to comment
Share on other sites

I was looking for something that simply disable/enable the wifi rather than disconnect the card....like when you use the function key on the laptop to enable/disable.

Edited by Champak
Link to comment
Share on other sites

Most of the time the FN button are proprietary, and are let up to the BIOS to interpret, which means you are essentially opting for option 1 and disabling power to the card.

Do have a read of http://en.wikipedia.org/wiki/Fn_key about that FN key, and the Send() documentation which reiterates:

Most laptop computer keyboards have a special Fn key. This key cannot be simulated.

Your specific vendor may offer software what has API's to the FN key commands, but your on your own there...

Link to comment
Share on other sites

The FN key is prob the simplest since it's built-in already (depending on your system config). Else here's a script I made once upon a time. It run's in the systray and toggles (enable/disable) your network interfaces.

Edited by spudw2k
Link to comment
Share on other sites

So here's my problem now and I need to figure a workaround. Sometimes "Internet Connection" gateway will be in my Network Connection and sometimes it wont which throws off my hotkey setup of calling the control ID of the trayitem. Or even in my other netbook where I have two wifi connections. My initial thought is to make a GUI populated by checkboxes created from an array of the networks detected. And then save the ones checked in some type of registry/ini. Problem is I don't want to do that because it would mean I would have to check the GUI every time I start the app up because sometimes a connection will show sometimes it wont...or it would be different between different laptops. Is there an automatic way to do this. I hope this made sense.

Here is my initial hotkey setup calling the function.

#include <Array.au3>
#include <GUIConstantsEx.au3>
;#include <Misc.au3>

Opt("TrayMenuMode",1)
TraySetIcon("Shell32.dll",-150)
TraySetToolTip("QuickNIC")


Global $colNetwork, $msg, $colNetwork
Global $strEnable = "En&able"
Global $strDisable = "Disa&ble"
Global $HotKey

;"!" = Alt
HotKeySet("!w", "_Wifi")
HotKeySet("!b", "_BlueTooth")
HotKeySet("!l", "_LocalArea")


Func NetworkConnectionsObject()
    $objShell = ObjCreate("Shell.Application")
    $strNetConn = "Network Connections"
    $objCP = $objShell.Namespace(3)
    Global $colNetwork = ""
    For $clsConn In $objCP.Items
        If $clsConn.Name = $strNetConn Then $colNetwork = $clsConn.GetFolder
    Next
    Return $colNetwork  
EndFunc

Func GetNetworkNames($colNetwork)
    Dim $strNetworks
    For $clsConn In $colNetwork.Items
        If StringInstr($clsConn.Name,"Wizard") = 0 Then
            $strNetworks = $strNetworks & $clsConn.Name & "|"
        EndIf
    Next
    $strNetworks = StringLeft($strNetworks,StringLen($strNetworks)-1)
    $arrNetworks = StringSplit($strNetworks,"|")
    _ArrayDelete($arrNetworks,0)
    _ArraySort($arrNetworks)
    Return $arrNetworks
EndFunc

Func AddTrayItems($arrNetworks)
    For $i = 0 To UBound($arrNetworks) - 1
        For $clsConn In $colNetwork.Items
            If $clsConn.Name = $arrNetworks[$i] Then
                TrayCreateItem($arrNetworks[$i])
                For $clsVerb in $clsConn.verbs
                    If $clsVerb.name = $strDisable Then TrayItemSetState(-1,1)
                    If $clsVerb.name = $strEnable Then TrayItemSetState(-1,4)
                Next
            EndIf
        Next
    Next
EndFunc

Func ToggleNetworkInterface($strNetwork)
    For $clsConn In $colNetwork.Items
        If $clsConn.Name = $strNetwork Then
            For $clsVerb in $clsConn.verbs
                If $clsVerb.name = $strDisable Then
                    If $HotKey = 1 Then
                        TrayItemSetState($msg, $GUI_UNCHECKED)
                        $HotKey = 0
                    EndIf
                    $clsVerb.DoIt
                    sleep(200)
                    Return 0
                EndIf
                If $clsVerb.name = $strEnable Then
                    If $HotKey = 1 Then
                        TrayItemSetState($msg, $GUI_CHECKED)
                        $HotKey = 0
                    EndIf
                    $clsVerb.DoIt
                    TrayItemSetState($msg,1)
                    sleep(200)
                    Return 1
                EndIf
            Next
        EndIf
    Next
EndFunc

AddTrayItems(GetNetworkNames(NetworkConnectionsObject()))

;#cs
$separator = TrayCreateItem("")
$trayabout = TrayCreateItem("About")
$trayexit = TrayCreateItem("Exit")
;#ce


Func _Wifi()
    $HotKey = 1
    $msg = 9
EndFunc

Func _LocalArea()
    $HotKey = 1
    $msg = 8
EndFunc

Func _BlueTooth()
    $HotKey = 1
    $msg = 7
EndFunc

While 1
    $msg = TrayGetMsg()

    If $msg > 0 and $msg <> $trayabout and $msg <> $trayexit Then 
        ConsoleWrite($msg & TrayItemGetText($msg) & @CRLF)
        ToggleNetworkInterface(TrayItemGetText($msg))
    EndIf
;#cs
    If $msg = $trayabout Then 
        SplashTextOn("About...","QuickNIC is a tool that provides a quick and easy method to toggle (enable/disable) your Network Connections." & @CRLF & @CRLF & "version 0.2b",300,120)
        sleep(3500)
        SplashOff()
    EndIf
;#ce        
    If $msg = $trayexit Then ExitLoop
WEnd

Then it all gets messed up if "Network Connection" Gateway shows up in the Network Connections. Is there a better way to accomplish what I want besides what I'm planning?

Edited by Champak
Link to comment
Share on other sites

The way to do it with no workarounds is through WlanSetInterface using the wlan_intf_opcode_radio_state opcode.

http://msdn.microsoft.com/en-us/library/ms706791(v=VS.85).aspx

The UDF I'm working on does not include this yet as the minimum supported client is vista - I'm still trying to reach comprehensive XP support!

If all goes to plan it should make an appearance in version 4 which will hopefully be released later this year. Gotta first sort out the mess that is version 3 :idea:

Much of the funtionality of this API is built into netsh though (command line) from vista on... so it may be worth checking that out. "that simple thing" is simply not built natively into XP... It is all proprietary software unfortunately.

Happy coding

Matt

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...