Eric said:
I've been trying to figure out how to have Windows automatically disable my
wireless connection whenever I am connected through a LAN line. I'd like it
to re-enable the wireless connection upon removing the LAN line. I read
about changing metric values for multiple connections but is there a better
way to jus simply automatically disable the wireless?
Thanks.
I just finished this script for a client of mine... seems to work.
You will need Devcon somewhere in the path. The VPN check is due to
the fact that it is a non-wireless connection - and therefore should be
ignored when assessing if a truly wired connection is present. Watch
for wrapped lines.... Jonathan
On Error Resume Next
Dim Shell, FSO, NICSet(30,4)
strComputer = "."
Set Shell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Service = Locator.ConnectServer(,"root\wmi")
RunPath = FSO.GetParentFolderName(WScript.ScriptFullName)
If RunPath = "" Then RunPath = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set AdapterItems = objWMIService.ExecQuery("SELECT * FROM
Win32_NetworkAdapter where NetConnectionStatus = 2",,48)
NICIndex = 0
FoundLANConnection = False
FoundWirelessConnection = False
For Each AItem in AdapterItems
NICIndex = NICIndex + 1
NICSet(NICIndex,1) = AItem.Name
NICSet(NICIndex,2) = GetIP(AItem.Index)
NICSet(NICIndex,3) = False
NICSet(NICIndex,3) = CheckWireless(AItem.Name)
NICSet(NICIndex,4) = AItem.PNPDeviceID
If NICSet(NICIndex,3) = False and Instr(NICSet(NICIndex,1),"VPN") =
0 Then
FoundLANConnection = True
End If
If NICSet(NICIndex,3) = True Then
FoundWirelessConnection = True
End If
Next
If FoundLANConnection = True and FoundWirelessConnection = True Then
For X = 1 to NICIndex
If NICSet(X,3) = True Then
Msgbox "Disabling Wireless Card: " & NICSet(X,1), vbOKOnly,
"Status"
DeviceBits = Split(NICSet(X,4),"&")
Shell.Run "Devcon Disable *" & DeviceBits(1) & "*", 0 ,
True
End If
Next
Else
Msgbox "No Wireless Connections Need Disabling ", vbOKOnly,
"Status"
End If
WScript.Quit
Function GetIP(IIndex)
Set ConfigItems = objWMIService.ExecQuery("SELECT * FROM
Win32_NetworkAdapterConfiguration where Index = " & IIndex,,48)
For Each CItem in ConfigItems
If IsArray(CItem.IPAddress) Then GetIP = CItem.IPAddress(0)
Next
End Function
Function CheckWireless(NICName)
CheckWireless = False
Set WNIC=Service.InstancesOf("MSNdis_80211_WEPStatus")
For Each WNICI in WNIC
If NICName = WNICI.InstanceName Then
CheckWireless = True
Exit Function
End If
Next
End Function