Software Archive
Read-only legacy content
17061 Discussions

Enable/Disable Wireless LAN Radio via command-line

scott_foster
Beginner
2,715 Views

I have been researching this topic for some time now. I need to be able to enable wireless for my users while they are on the road - many hotels and other locations only provide wireless connectivity. Because an active radio is a security risk, I want to disable them all of the time except when a user specifically enables them.

I've determined that I can do this with logon/logoff and startup/shutdown scripts on XP if I can disable the 2200BG or 3945ABG radio via the command-line. Not all of my laptops support a key-style disabling of the radio (nor do I trust my users to remember to turn their radios off when they are finished).

My point - I have been looking for an applet or hook into a DLL that would allow me to shut the Intel radio off. I've downloaded the Mobile SDK and tried to write a C# applet that would do this, but it did not work. I know there must be something as when you bring up the hardware properties for the Intel Wireless Device, you can shut the radio on and off from inside that applet. There must be a hook somewhere...

If you don't mind, please either provide me with an applet that can enable or disable the radio by passing a command-line parameter, or share with me the secret to this.

Thanks,

Scott Foster

0 Kudos
11 Replies
cluther962
Beginner
2,715 Views

Hey, Scott. I'm in the same boat as you. I've created a WMI script that works under Windows Server 2003, Vista, and supposedly Longhorn but the Enable and Disable methods are not available under the Windows XP WMI implementation.

I'll be watching this thread but would be interested in the C# code you wrote, if you're inclined to share that is.

Regards,

- Christopher

0 Kudos
markndawn
Beginner
2,715 Views

Christopher,
I would really like to see the script you wrote, would you mind sharing? I am experiencing something similar.....

Thanks!
Mark

0 Kudos
cluther962
Beginner
2,715 Views

Mark,

As I am unable to attach files to these forum posts, here is the WMI VBscript source to disable a specific Wi-Fi adapter:

' Script: "Disable Wi-Fi Adapter.vbs"
' Date: 16-Apr-2007
'
' This WMI script enables a specific (e.g., named) Wi-Fi adapter.
'

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & strComputer & " ootcimv2")

set colAdapters = objWMIService.Execquery("Select * from Win32_NetworkAdapter")
For Each Adapter in colAdapters
WScript.Echo Adapter.DeviceId & " " & Adapter.Name & " " & "Status: " & Adapter.Status

' Identify the specific adapter to disable
If Adapter.name = "Dell TrueMobile 1300 WLAN Mini-PCI Card" Then

' Note: the Disable() method does not exist under Windows XP.
errReturn = Adapter.Disable()
If errReturn <> 0 Then
WScript.Echo "Disable Network adapter failed for adapter: " & Adapter.DeviceId
Else
WScript.Echo "Disable Network adapter succeeded for adapter: " & Adapter.DeviceId
End If

WScript.Echo "NetEnabled: " & Adapter.NetEnabled
End If
Next

And here is the WMI VBscript source to enable a specific Wi-Fi adapter:

' Script: "Enable Wi-Fi Adapter.vbs"
' Date: 16-Apr-2007
'
' This WMI script disables a specific (e.g., named) Wi-Fi adapter.
'

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & strComputer & " ootcimv2")

set colAdapters = objWMIService.Execquery("Select * from Win32_NetworkAdapter")
For Each Adapter in colAdapters
WScript.Echo Adapter.DeviceId & " " & Adapter.Name & " " & "Status: " & Adapter.Status

' Identify the specific adapter to enable
If Adapter.name = "Dell TrueMobile 1300 WLAN Mini-PCI Card" Then

' Note: the Enable() method does not exist under Windows XP.
errReturn = Adapter.Enable()
If errReturn <> 0 Then
WScript.Echo "Enable Network adapter failed for adapter: " & Adapter.DeviceId
Else
WScript.Echo "Enable Network adapter succeeded for adapter: " & Adapter.DeviceId
End If

WScript.Echo "NetEnabled: " & Adapter.NetEnabled
End If
Next

You could easily modify the script to accept command line parameters so that the functionality is more generic.

Enjoy!

- Christopher

0 Kudos
markndawn
Beginner
2,715 Views

Christopher,

Thank you for the quick response and the code, I really appreciate it....

Mark

0 Kudos
markndawn
Beginner
2,715 Views

Christopher,
Thanks again for sharing, this was perfect. Where I am there are also Windows 2000 machines (yes, we still have some). As with XP, 2K doesn't support the Win32_NetworkAdapter WMI class.

Are you aware of any other methods?
Thanks again, Mark

0 Kudos
cluther962
Beginner
2,715 Views

Hi, Mark.

Unfortunately, the WMI implementations under XP and W2K are rather crippled. The only other option I've seen is to attempt to work with the various Wi-Fi card vendors who produce a SDK and attempt to write something specific to an adapter.

Sorry...

- Christopher

0 Kudos
bill_castner
Beginner
2,715 Views

To do this under Win2k/XP you need to download and use Devcon.exe, a command line
version of Device Manager: http://support.microsoft.com/kb/311272

Place devcon.exe in your PATH, such as WindowsSystem32

Then you have full access to true Disable/Enable commands for any
device in your batch file, without user mistakes being a possible
issue.

For both .bat or .cmd files, you need to pass the "hwid", which is
more than a little obscure.

From a Start, Run, CMD session as Administrator (for XP Home, do this
with a logon as Administrator in Safe Mode):

; ask devcon.exe to expose the hwid for all network adapters:
devcon hwids =net
;
; for my notebook it returned four for the wireless card:
PCIVEN_14E4&DEV_4320&SUBSYS_43201737&REV_03
PCIVEN_14E4&DEV_4320&SUBSYS_43201737
PCIVEN_14E4&DEV_4320&CC_028000
PCIVEN_14E4&DEV_4320&CC_0280

It does not matter. Any of them will do. I will use the last entry in
this example as it is shorter.

For the desktop shortcut link to Wireless_Off the .CMD file contains
the following:
;
; Wireless_Off.cmd
;
; A shortcut for the desktop will be created to disable wireless from this file
;
@echo off
echo Disabling the wireless adapter...................
devcon disable PCIVEN_14E4&DEV_4320&CC_0280
echo Done................
;
; EOF

Similarly, to create a desktop shortcut to re-enable the device, a
second .BAT or .CMD file needs to be created.

;
; Wireless_On.cmd
;
; A shortcut for the desktop will be created to ENABLE wireless from this file
;
@echo off
echo Enabling the wireless adapter ...............
devcon enable PCIVEN_14E4&DEV_4320&CC_0280
echo Done................
;
; EOF

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

Once you use the earlier instruction to discover the hwid of the
wireless adapter, the rest is simple.

0 Kudos
cluther962
Beginner
2,715 Views

Thanks, Bill. I'll download the cli version of Device Manager and start testing.

- Christopher

0 Kudos
geoff_s
Beginner
2,715 Views

Bill -- Thanks for this tip. This worked for me in regards to enabling/disabling my wifi device...

However would you have an idea of how to modify it to disable/enable the radio for that device rather than disabling/enabling the actual device? I tried various arguments with no luck.

Thanks!

EDIT: To further clarify, in the regular Win XP Device Manager I can go to Properties and then Advanced. Once there, say for my Wifi card, I can go to the 'Property' Radio Enable/Disable and then select the 'Value' as Enabled or Disabled. I have gone through the DevCon documentation and I don't seem to see that it has the ability to do this. Am I correct on this or can you correct me?

0 Kudos
Anonymous4
Beginner
2,715 Views

Bill, Chris,

I read your postings about how to make a batch file to disable and enable your wireless devices using batch files or VB scripts and I wondered to myself, is there a way to do both with one batch file? Well there has to be, so I spent some time tonight and improved on your idea... Which made it easier to run a shortcut to a hotkey on my Keybaord...

This is what I came up with...

NOTE: some of this was just playing around with various commands to see the result, but I decided to keep it in there cause there are always the ID10T's that just copy/past but don't read...

Hope this helps! Ben

ECHO OFF
CLS
ECHO Checking Wireless Adapter.....
devcon status PCIVEN_168C>c:wireless.txt 2>&1
; In this section I ran a status check onmy wireless adapter then PRINTED it to a txt file

IF ERRORLEVEL ==1 GOTO Q

; Here it checks for any errors when attempting to run devcon, if it finds one it sends youdown to "Q" where it informs you of the problem and asks to send you to the MS website...
find /c "disabled." c:wireless.txt

; here it searches for the string "Disabled." in the txt file, and it what the file above will say if it is there. If it finds "Disabled."
CLS
ECHO Checking Wireless Adapter.....
IF ERRORLEVEL ==1 GOTO D
GOTO E

then is sendsto "E" where itenablesthe device. If not found it send to "D" where itdisablesthe device.

:D
ECHO Disabing Wireless card.....
devcon disable PCIVEN_168C
GOTO Z

:Q
CLS
ECHO Error:
ECHO You must first download DevCon command-line utility from Microsoft's website
ECHO then place it in your windowssystem32 folder.
set choice=
set /p choice=TO go there now, press the "1" Key, or press any other key to exit...
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' GOTO IE
GOTO Z

:IE
START /MAX c:progra~1intern~1iexplore.exe
http://support.microsoft.com/kb/311272
GOTO Z

:E
ECHO Enabing Wireless card.....
devcon enable PCIVEN_168C

:Z
del /Q wireless.txt
ECHO Done.
@ECHO ON

0 Kudos
jobs__carreer
Beginner
2,715 Views

follow this step

Open Start.

Search for Command Prompt, right-click the top result, and select Run as administrator.

Type the following command to identify the name of the adapter you want to disable and press Enter: ...

Type the following command to disable the Wi-Fi or Ethernet adapter and press Enter:

anyone searching for a job visit here careerjobs360 for more details.

0 Kudos
Reply