Distrophy Posted July 31, 2008 Share Posted July 31, 2008 (edited) I need help removing network adapters that are not currently "in use" on a computer. I am constantly moving laptops between multiple docks, and each dock detects as a different 'virtual' network adapter, but i want some code to run when my program detects that it has been hooked into a new dock. I need to remove the old network adapters so that when i return the laptop to a dock it has been in before, it will detect that as a new connection and run the rest of my code. Is there an easier way around that problem? I've tried removing adapters from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{ } and from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards but that just causes issues and the connections never re-detect. Thanks. Edited August 2, 2008 by Distrophy Link to comment Share on other sites More sharing options...
Distrophy Posted August 2, 2008 Author Share Posted August 2, 2008 (edited) I figured it out a better way. This gets the MAC's of active adapters and compares it with the last known one stored in the registry. CODE #include <Constants.au3> Func FindActiveAdapters() $Active = FindActive() ;load list of active adapters into array For $i = 0 To UBound($Active) - 1 If StringInStr($Active[$i][1], "Realtek") Then ;look for realtek adapters in active list $vLastActive = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MAC_Check", "LastActiveMAC") ;load last used MAC address into variable If Not $vLastActive = $Active[$i][0] Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\MAC_Check", "LastActiveMAC", "Reg_SZ", $Active[$i][0]) ;if different, then write the new mac in registry WriteReg() Else ;if same, do nothing EndIf EndIf Next EndFunc ;==>FindActiveAdapters Func FindActive() $getMAC = Run("cmd.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($getMAC, "ipconfig/all" & @CRLF) StdinWrite($getMAC) ; Read from child's STDOUT Local $data Local $MACArray[1][2] While True $data &= StdoutRead($getMAC) If @error Then ExitLoop Sleep(25) WEnd If $data <> '' Then $ipline = StringSplit(StringReplace($data, @LF, ''), @CR) ;break feed into lines $i = 0 For $n = 1 To $ipline[0] If StringInStr($ipline[$n], "Description . . . . . . . . . . . :") <> "0" Then ;find lines with adapter description $ipresult = StringReplace(StringTrimLeft($ipline[$n], 44), "-", "") ;~ ConsoleWrite($ipresult & @CRLF) ReDim $MACArray[1 + $i][2] ;redim the array for each new value found $MACArray[$i][1] = $ipresult EndIf If StringInStr($ipline[$n], "Physical Address. . . . . . . . . :") <> "0" Then ;find lines with MAC addresses $ipresult = StringReplace(StringTrimLeft($ipline[$n], 44), "-", "") ;~ ConsoleWrite($ipresult & @CRLF) $MACArray[$i][0] = $ipresult $i = $i + 1 ;increment counter EndIf Next ;~ _ArrayDisplay($MACArray) EndIf Return $MACArray EndFunc ;==>FindActive Edited August 2, 2008 by Distrophy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now