VBScript to Disable Devices with Devcon

The following VBScript can be used as an example for disabling devices with Microsoft’s devcon utility.

'==========================================================================
' NAME: DisableWifi
' AUTHOR: Nick Moseley, http://t3chn1ck.wordpress.com
' COMMENT: Determines if a network adapter device is wireless/wifi and then
' executes a devcon command to disable the device
' VERSION HISTORY:
' 1.0 (05/13/2011) - Initial Script
' 2.0 (05/25/2011) - Added logging into registry for future inventory
'==========================================================================
Option Explicit
Const ForAppending = 8

Dim oWMI, oShell, colItems, oFSO, oFile
Set oShell = CreateObject ("WScript.Shell")
Set oWMI = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = oWMI.ExecQuery ("Select * from Win32_PnPEntity where name like '%wireless%' or name like '%wifi %'")

'Start logging
Set oFSO = CreateObject("Scripting.fileSystemObject")
Set oFile = oFSO.OpenTextFile ("C:\Windows\Temp\WifiLog.txt", ForAppending, True)
oFile.WriteLine "Disable wireless network adapter"
oFile.WriteLine " => Started (" & Date & " " & Time & ")"

' If count=0 of the collection, then no wireless devices found
If colItems.count=0 Then
 oFile.WriteLine " => WARNING: Wireless network adapter not found!"
Else
 Dim oItem, sDeviceType
 WScript.Echo Wscript.ScriptFullName & "\devcon\i386\devcon.exe "
 oFSO.CopyFile oFSO.GetFile(Wscript.ScriptFullName).ParentFolder & "\devcon\i386\devcon.exe ", "C:\Windows\Temp\devcon.exe"
 ' Parse the collection of wireless devices to be disabled
 For Each oItem In colItems
 sDeviceType = UCase(Left(oItem.DeviceID, 3))
 If sDeviceType = "PCI" Then
 oShell.Run "C:\Windows\Temp\devcon.exe disable ""@" & oItem.deviceID & ""
 oFile.WriteLine " => Disabled " & oItem.Name
 oFile.WriteLine " Device ID: " & oItem.DeviceID
 End If
 Next
End If

' Set registry values for SCCM inventory
oShell.RegWrite "HKLM\Software\CompanyName\ImageInfo\DisabledWirelessNIC", "True", "REG_SZ"

' End
oFile.WriteLine " => Completed (" & Date & " " & Time & ")"
WScript.Quit (oFile.Close)
email

Written by , Posted .