Welcome to Intel® Software Network Quick Login | Join | Help |
Search in Intel® Software Network Forums
in Go

Enable/Disable Wireless LAN Radio via command-line

Last post 10-07-2007, 9:48 PM by d2_ricci@yahoo.com. 10 replies.
Sort Posts: Previous Next
 04-13-2007, 1:36 PM 30233496  

Enable/Disable Wireless LAN Radio via command-line

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

 

 
 04-17-2007, 11:33 AM 30233598 in reply to 30233496  

Re: Enable/Disable Wireless LAN Radio via command-line

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

 
 04-27-2007, 9:21 AM 30233979 in reply to 30233598  

Re: Enable/Disable Wireless LAN Radio via command-line

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

 

Thanks!
Mark

 

 
 04-27-2007, 9:38 AM 30233980 in reply to 30233979  

Re: Enable/Disable Wireless LAN Radio via command-line

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 & "\root\cimv2")

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 & "\root\cimv2")

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

 

 
 04-30-2007, 4:58 AM 30234025 in reply to 30233980  

Re: Enable/Disable Wireless LAN Radio via command-line

Christopher,

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

 

 

Mark

 

 
 04-30-2007, 7:18 PM 30234060 in reply to 30233980  

Re: Enable/Disable Wireless LAN Radio via command-line

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

 
 05-01-2007, 9:35 AM 30234078 in reply to 30234060  

Re: Enable/Disable Wireless LAN Radio via command-line

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

 

 
 05-02-2007, 4:08 PM 30234118 in reply to 30234078  

Re: Enable/Disable Wireless LAN Radio via command-line

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 \Windows\System32

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:
      PCI\VEN_14E4&DEV_4320&SUBSYS_43201737&REV_03
      PCI\VEN_14E4&DEV_4320&SUBSYS_43201737
      PCI\VEN_14E4&DEV_4320&CC_028000
      PCI\VEN_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 PCI\VEN_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 PCI\VEN_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.

 
 05-05-2007, 3:50 PM 30234229 in reply to 30234118  

Re: Enable/Disable Wireless LAN Radio via command-line

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

- Christopher

 

 
 05-07-2007, 9:00 AM 30234252 in reply to 30234118  

Re: Enable/Disable Wireless LAN Radio via command-line

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?

 
 10-07-2007, 9:48 PM 30241711 in reply to 30234118  

Re: Enable/Disable Wireless LAN Radio via command-line

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 PCI\VEN_168C>c:\wireless.txt 2>&1
; In this section I ran a status check on my 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 you  down 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 sends to "E" where it enables the device. If not found it send to "D" where it disables the device. 

:D
ECHO Disabing Wireless card.....
devcon disable PCI\VEN_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 windows\system32 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~1\intern~1\iexplore.exe
http://support.microsoft.com/kb/311272
GOTO Z

:E
ECHO Enabing Wireless card.....
devcon enable PCI\VEN_168C

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

 
View as RSS news feed in XML

Shortcuts


Tags For This Post

...

Community Tags

...