Script VBS permettant de désactiver ou d’activer une carte réseau sous Windows

Posted by Cereal Wednesday, November 08, 2006 6:00:00 AM Categories: _Tous les articles Tools / Utilitaires VBS / Scripting Windows 2003 Windows XP
Rate this Content 0 Votes

Script VBS permettant de désactiver ou d'activer une carte réseau en fonction de son état, si la carte est activée le script va la désactiver si la carte est désactivée le script va l'activer.

Pour la configuration du script voir l'article :
Ping une adresse IP et si pas de réponse Désactive puis Active la connexion réseau

Download : DisableEnableNetworkCard.zip (4ko)

'List the available control panel in Windows
For Each oControlPanel In oControlPanels.items
'Show the available control panels
'WScript.Echo oControlPanel.name

'If the control panel is = the constant
If oControlPanel.name = cNetPannelName Then
'Set the focus on the control panel
Set oNetworkConn = oControlPanel.getfolder
'Message
WScript.Echo "Found the control panel : " & cNetPannelName
Exit For
End if
Next

'If not find
If oNetworkConn Is Nothing Then
MsgBox "Could not find [Network Connection] folder"
WScript.Quit
End If


Set oLanConn = Nothing
For Each oControlPanel In oNetworkConn.items
If Lcase(oControlPanel.name) = Lcase(sConnectionName) Then
'Show the result
'WScript.Echo "The variables match [" & Lcase(oControlPanel.name) & "]=[" & Lcase(sConnectionName) & "]"
WScript.Echo "Found the connection name : " & oControlPanel.name

Set oLanConn = oControlPanel
Exit For
End if
Next

'If not find
If oLanConn Is Nothing Then
MsgBox "Could not find '" & sConnectionName & "' item"
WScript.Quit
end if


bEnabled = True
Set oEnableLAN = Nothing
Set oDisableLAN = Nothing
sTMP = "verbs: " & VbCrLf

'Check the state of Network Card
For Each oVerb In oLanConn.verbs
sTMP = sTMP & vbcrlf & oVerb.name
'Show the list of verbs
'WScript.Echo sTMP

If oVerb.name = cENABLE Then
WScript.Echo "The network card is [Disabled]"
Set oEnableLAN = oVerb
bEnabled = False
End If
If oVerb.name = cDISABLE Then
WScript.Echo "The network card is [Enabled]"
Set oDisableLAN = oVerb
End If
Next

'Enable or Disable the Network Card
If bEnabled Then
'oLanConn.invokeverb cDISABLE
WScript.Echo "Disable the network card"
oDisableLAN.DoIt
Else
'oLanConn.invokeverb cENABLE
WScript.Echo "Enable the network card"
oEnableLAN.DoIt
End If
Wscript.Sleep 2000

Simple-Tech.info
Site Map | Printable View | © 2008 - 2012 Simple-Tech.info | Powered by mojoPortal | HTML 5 | CSS | Design by mitchinson