Código: Seleccionar todo
Global Const $NCME_DEFAULT = 0
Global Const $S_OK = 0
Global Const $sCLSID_ConnectionManager = '{BA126AD1-2166-11D1-B1D0-00805FC1270E}'
Global Const $sIID_INetConnectionManager = '{C08956A2-1CD3-11D1-B1C5-00805FC1270E}'
Global Const $sIID_IEnumNetConnection = '{C08956A0-1CD3-11D1-B1C5-00805FC1270E}'
Global Const $sIID_INetConnection = '{C08956A1-1CD3-11D1-B1C5-00805FC1270E}'
Global Const $sINetConnectionManager = "EnumConnections hresult(int;ptr*)"
Global Const $sTag_IEnumNetConnection = "Next hresult(int;ptr*;ulong*)"
Global Const $sTag_INetConnection = "Connect hresult();Disconnect hresult();Delete hresult();Duplicate hresult(wstr;ptr*);GetProperties hresult(ptr)"
Global Const $sTag_NETCON_PROPERTIES = "byte guidId[16];ptr pszwName;ptr pszwDeviceName;dword Status;dword MediaType;dword dwCharacter;byte clsidThisObject[16];byte clsidUiObject[16]"
Func NetWorkEnableDisable($sNetWorkName, $bEnable_Disable = true)
Local $hResult = 0
Local $iCount = 0
Local $pIEnumNetConnection = 0
Local $oIEnumNetConnection = 0
Local $pConnection = 0
Local $tNETCON_PROPERTIES = 0
Local $tName = 0
Local $sNetName = ""
Local $tDeviceName = 0
Local $oConnection = 0
Local $pPROPERTIES = 0
Local $tPtr = 0
Local $iState=0
Local $oNetCManager = ObjCreateInterface($sCLSID_ConnectionManager, $sIID_INetConnectionManager, $sINetConnectionManager)
If IsObj($oNetCManager) Then
ConsoleWrite("$oNetCManager:" & IsObj($oNetCManager) & @CRLF)
$oNetCManager.EnumConnections($NCME_DEFAULT, $pIEnumNetConnection)
If $pIEnumNetConnection Then
ConsoleWrite("$pIEnumNetConnection: " & $pIEnumNetConnection & @CRLF)
$oIEnumNetConnection = ObjCreateInterface($pIEnumNetConnection, $sIID_IEnumNetConnection, $sTag_IEnumNetConnection)
If IsObj($oIEnumNetConnection) Then
ConsoleWrite("$oIEnumNetConnection: " & IsObj($oIEnumNetConnection) & @CRLF)
While ($oIEnumNetConnection.Next(1, $pConnection, $iCount) = $S_OK)
ConsoleWrite("$pConnection: " & $pConnection & " $iCount: " & $iCount & @CRLF)
$oConnection = ObjCreateInterface($pConnection, $sIID_INetConnection, $sTag_INetConnection)
If IsObj($oConnection) Then
$tNETCON_PROPERTIES = DllStructCreate($sTag_NETCON_PROPERTIES)
$tPtr = DllStructCreate("ptr Pointer")
ConsoleWrite("$oConnection: " & IsObj($oConnection) & @CRLF)
$hResult = $oConnection.GetProperties(DllStructGetPtr($tPtr))
If SUCCEEDED($hResult) Then
$tNETCON_PROPERTIES = DllStructCreate($sTag_NETCON_PROPERTIES, $tPtr.Pointer)
$tName = DllStructCreate("wchar[260]", $tNETCON_PROPERTIES.pszwName)
$sNetName = DllStructGetData($tName, 1)
If $bEnable_Disable Then
If $sNetName = $sNetWorkName Then
If SUCCEEDED($oConnection.Connect()) Then
DllCall("netshell.dll", "none", "NcFreeNetconProperties", "ptr", DllStructGetPtr($tNETCON_PROPERTIES))
Return True
EndIf
EndIf
Else
If $sNetName = $sNetWorkName Then
If SUCCEEDED($oConnection.Disconnect()) Then
DllCall("netshell.dll", "none", "NcFreeNetconProperties", "ptr", DllStructGetPtr($tNETCON_PROPERTIES))
Return True
EndIf
EndIf
EndIf
DllCall("netshell.dll", "none", "NcFreeNetconProperties", "ptr", DllStructGetPtr($tNETCON_PROPERTIES))
$tPtr = 0
$tName = 0
$tNETCON_PROPERTIES = 0
$oConnection = 0
Else
Return False
EndIf
Else
Return False
EndIf
WEnd
Else
Return False
EndIf
Else
Return False
EndIf
Else
Return False
EndIf
EndFunc ;==>NetWorkEnableDisable
Func SUCCEEDED($hr)
Return ($hr >= 0)
EndFunc ;==>SUCCEEDED
Saludos