Tentaal Posted May 16, 2007 Share Posted May 16, 2007 Hello, Here is a code that tell the user when a network adapter has changed its status. Now, I want to find a way to disable a network card. I do not want to use tool like devcon.exe. It must be done by using WMI. How can I do it? Thanks! $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_NetworkAdapter'") While 1 $objEvent = $colEvents.NextEvent if $objEvent.Path_.Class()="__InstanceModificationEvent" Then ; on teste si le statut de la carte réseau a changé If $objEvent.TargetInstance.NetConnectionStatus <> $objEvent.PreviousInstance.NetConnectionStatus Then Select Case $objEvent.TargetInstance.NetConnectionStatus = 2 MsgBox(0, "Enable", "Interface was enabled : " & $objEvent.TargetInstance.Name) Case $objEvent.TargetInstance.NetConnectionStatus = 0 MsgBox(0, "Disable", "Interface was disabled : " & $objEvent.TargetInstance.Name) EndSelect EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 16, 2007 Share Posted May 16, 2007 Hi, disable or just cut the connection? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Tentaal Posted May 16, 2007 Author Share Posted May 16, 2007 Hi,disable or just cut the connection?So long,MegaHi,Disable the device. Link to comment Share on other sites More sharing options...
ptrex Posted May 16, 2007 Share Posted May 16, 2007 @TentaalA question we hear frequently is "How do I enable and disable my network adapters through a script?" Well, we won't hold you in suspense. We'll tell you right now that you can't. At least not until you're running Windows Vista. In Windows Vista two new methods have been added to the Win32_NetworkAdapter class: Enable and Disable.Sorry Regards,ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Danny35d Posted May 17, 2007 Share Posted May 17, 2007 The NicToggle() UDF was made by Wus expandcollapse popup#include <GUIConstants.au3> Dim $i, $base, $key, $name ; == GUI generated with Koda == $Form1 = GUICreate("Nic", 176, 89, -1, -1, -1, $WS_EX_TOOLWINDOW) GUICtrlCreateLabel("Pick Network Connection", 8, 8, 157, 17, $SS_CENTER) $Combo1 = GUICtrlCreateCombo("", 8, 24, 161, 21) $Button1 = GUICtrlCreateButton("Enable", 8, 56, 75, 25) $Button2 = GUICtrlCreateButton("Disable", 96, 56, 75, 25) ;Get Network Connection Names $base = "HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}" While 1 $i += 1 $key = RegEnumKey($base, $i) If @error <> 0 Then ExitLoop $name = RegRead($base & "\" & $key & "\Connection", "Name") If StringLeft($key, 1) = "{" Then GUICtrlSetData($Combo1, $name & "|") WEnd GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 If GUICtrlRead($Combo1) <> '' Then NicToggle(1, GUICtrlRead($Combo1)) Case $Button2 If GUICtrlRead($Combo1) <> '' Then NicToggle(0, GUICtrlRead($Combo1)) Case Else ;;;;;;; EndSwitch WEnd Exit Func NicToggle($Toggle, $sConnectionName = "Local Area Connection", $sNetworkFolder = "Network Connections") $ssfCONTROLS = 3 $sEnableVerb = "En&able" $sDisableVerb = "Disa&ble" $shellApp = ObjCreate("shell.application") $oControlPanel = $shellApp.Namespace ($ssfCONTROLS) $oNetConnections = "nothing" For $folderitem In $oControlPanel.items If $folderitem.name = $sNetworkFolder Then $oNetConnections = $folderitem.getfolder ExitLoop EndIf Next If $oNetConnections = "nothing" Then MsgBox(48, "Error", "Couldn't find " & $sNetworkFolder & " folder") Exit EndIf $oLanConnection = "nothing" For $folderitem In $oNetConnections.items If StringLower($folderitem.name) = StringLower($sConnectionName) Then $oLanConnection = $folderitem ExitLoop EndIf Next If $oLanConnection = "nothing" Then MsgBox(48, "Error", "Couldn't find '" & $sConnectionName & "' item") Exit EndIf $bEnabled = True $oEnableVerb = "nothing" $oDisableVerb = "nothing" $s = "Verbs: " & @CRLF For $verb In $oLanConnection.verbs $s = $s & @CRLF & $verb.name ;enables If $verb.name = $sEnableVerb And $Toggle = 1 Then $oEnableVerb = $verb $oEnableVerb.DoIt ExitLoop ;disables ElseIf $verb.name = $sDisableVerb And $Toggle = 0 Then $oDisableVerb = $verb $oDisableVerb.DoIt ExitLoop Else MsgBox(48, "Error", "Tried to disable when already disabled" & @CRLF & "or enable when already enabled") Exit EndIf Next Sleep(1000) EndFunc ;==>NicToggle AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line 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