News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Turn off WiFi adaptor

Started by Magnum, February 27, 2013, 11:48:08 AM

Previous topic - Next topic

Magnum

I am looking to write some code to turn off my Wifi adaptor.

I used devcon, but it turned off other needed services.

Intel Wifi 5100 link

I would like to be able to quickly turn it off and then back on later.

I think it would use these includes and library.

Thanks.

Wlanapi.inc
Wlanapi.lib

WlanOpenHandle
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

sinsi

I just used to stop the WLANSVC service, then restart it later.

Magnum

Do you mean Wireless Zero Configuration ?

Provides automatic configuration for the 802.11 adapters
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

sinsi


Magnum

It did not work.

I found this for the Wireless Zero Configuration.

Service name: WZCSVC

D:\WINDOWS\System32\svchost.exe -k netsvcs
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

sinsi

Might be called something different in XP, mine is for win7.

mywan

Quote from: Magnum on February 27, 2013, 03:15:20 PM
It did not work.

I found this for the Wireless Zero Configuration.

Service name: WZCSVC

D:\WINDOWS\System32\svchost.exe -k netsvcs
It looks like a simple matter of chanching "WLANSVC" in the source code to "WZCSVC", or whatever service you want it to stop. Even better would be to pass the service name in as a command line parameter.

dedndave

i suppose you might look at WMI

http://msdn.microsoft.com/en-us/library/Aa394595

here is a solution that seems to work for one guy
scroll down to "Solution 4"
i guess that's visual basic   :P

http://www.codeproject.com/Questions/151446/How-to-disable-or-enable-a-network-adapter

Magnum

Quote from: mywan on February 27, 2013, 04:38:19 PM
Quote from: Magnum on February 27, 2013, 03:15:20 PM
It did not work.

It looks like a simple matter of chanching "WLANSVC" in the source code to "WZCSVC", or whatever service you want it to stop. Even better would be to pass the service name in as a command line parameter.

Using WZCSVC did not work, but I am interested in learning how to pass the service name in as a command line parameter.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

This one way that works.

If someone could test this on Win 2000, 7, and 8 as well.



'Start_wifi.vbs If you are using DHCP, this will renew all DHCP leases
'               and reenable Internet access
'               http://msdn.microsoft.com/en-us/library/Aa394595
strComputer = "."
Set objWMIService = GetObject( _
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration " _
        & "Where IPEnabled = True")
For Each objNetCard in colNetCards
     objNetCard.RenewDHCPLease()
Next

---------------------------------------

'Stop_wifi.vbs  If you are using DHCP, this will release the IP address
'               and disable Internet access
'     http://msdn.microsoft.com/en-us/library/Aa394595
strComputer = "."
Set objWMIService = GetObject( _
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration " _
        & "Where IPEnabled = True")
For Each objNetCard in colNetCards
    objNetCard.ReleaseDHCPLease()
Next
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

In stepping thru, did not see any errors.


; Shutdown wireless service    Written by sinsi - Mod 1
;
include \masm32\include\masm32rt.inc
include \masm32\include\advapi32.inc
includelib \masm32\lib\advapi32.lib

.const
wlansvc db 'C:\WINDOWS\System32\svchost.exe -k netsvcs',0

.data?
status SERVICE_STATUS <>

.code
stopservice:
        sub ebx,ebx
        sub esi,esi
        sub edi,edi
        invoke OpenSCManager,0,0,SC_MANAGER_ALL_ACCESS
        test eax,eax
        jz @f
        mov ebx,eax
        invoke OpenService,ebx,offset wlansvc,SERVICE_STOP
        test eax,eax
        jz @f
        mov esi,eax
        invoke ControlService,esi,SERVICE_CONTROL_STOP,offset status
        test eax,eax
        jz @f
        inc edi
        @@:
        test esi,esi
        jz @f
        invoke CloseServiceHandle,esi
        @@:
        test ebx,ebx
        jz @f
        invoke CloseServiceHandle,ebx
        @@:
        mov eax,edi
        ret

startservice:
        sub ebx,ebx
        sub esi,esi
        sub edi,edi
        invoke OpenSCManager,0,0,SC_MANAGER_ALL_ACCESS
        test eax,eax
        jz @f
        mov ebx,eax
        invoke OpenService,ebx,offset wlansvc,SERVICE_START
        test eax,eax
        jz @f
        mov esi,eax
        invoke StartService,esi,0,0
        test eax,eax
        jz @f
        inc edi
        @@:
        test esi,esi
        jz @f
        invoke CloseServiceHandle,esi
        @@:
        test ebx,ebx
        jz @f
        invoke CloseServiceHandle,ebx
        @@:
        mov eax,edi
        ret

start:  call stopservice
        inkey
        call startservice
        invoke ExitProcess,0

end start

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org