Prog en vb

progg Messages postés 166 Statut Contributeur -  
Pier-3d Messages postés 67 Date d'inscription   Statut Membre Dernière intervention   -
Bonjours à tous,
J'aimerais connaire les commandes me permettant d'activer et de désactivé un périphérique.
Merçi d'avance

4 réponses

  1. pdelf
     
    De quel peripherique s'agit-il exactement?
    0
  2. progg Messages postés 166 Statut Contributeur 8
     
    Il s'agit d'une carte réseau
    0
  3. eric
     
    sois plus explicite dans tes question?
    0
  4. progg Messages postés 166 Statut Contributeur 8
     
    j'aimerais désactiver ma carte réseau en utilisant un programme que j'aurais fait en vb
    0
    1. Pier-3d Messages postés 67 Date d'inscription   Statut Membre Dernière intervention   1
       
      J'ai un programme écrit en VB script et qui fait exactement
      cela. Il active (enable) la carte réseau ou l'inactive (desable)
      à chaque lancement. Donc avec une seule icône, j'active ou
      désactive ma carte réseau. Comme ça je peux facilement laisser
      mon ordinateur en marche sans risquer qu'un virus que j'aurais
      attrapper en profite pour se répandre à partir de chez moi.

      Ça a été écrit par quelqu'un de chez Microsoft ; trouvé sur un
      Newsgroup qq part.

      ' Bascule Connexion Internet - Allume ou éteind la carte 'Realtek Videotron'.

      Const ssfCONTROLS = 3

      Dim sConnectionName, sAppletName, sEnableVerb, sDisableVerb
      Dim ShellApp, oControlPanel, folderItem, oNetConnections
      Dim oLanConnection, bEnabled, oEnableVerb, oDisableVerb
      Dim verb, S

      sAppletName = "Network Connections" ' nom de l'applet de configuration Réseau du panneau de configuration
      sConnectionName = "realtek videotron" ' nom de la carte réseau

      sEnableVerb = "En&able"
      sDisableVerb = "Disa&ble"

      Set ShellApp = CreateObject("shell.application")
      Set oControlPanel = ShellApp.Namespace(ssfCONTROLS)

      Set oNetConnections = Nothing
      For Each folderItem In oControlPanel.items
      If folderItem.Name = sAppletName Then
      Set oNetConnections = folderItem.GetFolder: Exit For
      End If
      Next

      If oNetConnections Is Nothing Then
      MsgBox "Couldn't find 'Network Connections' folder"
      wscript.quit
      End If

      Set oLanConnection = Nothing
      For Each folderItem In oNetConnections.items
      If LCase(folderItem.Name) = LCase(sConnectionName) Then
      Set oLanConnection = folderItem: Exit For
      End If
      Next

      If oLanConnection Is Nothing Then
      MsgBox "Couldn't find '" & sConnectionName & "' item"
      wscript.quit
      End If

      bEnabled = True
      Set oEnableVerb = Nothing
      Set oDisableVerb = Nothing
      S = "Verbs: " & vbCrLf
      For Each verb In oLanConnection.verbs
      S = S & vbCrLf & verb.Name

      If verb.Name = sEnableVerb Then
      Set oEnableVerb = verb
      bEnabled = False
      End If
      If verb.Name = sDisableVerb Then
      Set oDisableVerb = verb
      End If
      Next

      'debugging displays left just in case...
      '
      'msgbox s ': wscript.quit
      'msgbox "Enabled: " & bEnabled ': wscript.quit

      'not sure why, but invokeverb always seemed to work
      'for enable but not disable.
      '
      'saving a reference to the appropriate verb object
      'and calling the DoIt method always seems to work.
      '
      If bEnabled Then
      ' oLanConnection.invokeverb sDisableVerb
      oDisableVerb.DoIt
      Else
      ' oLanConnection.invokeverb sEnableVerb
      oEnableVerb.DoIt
      End If

      'adjust the sleep duration below as needed...
      '
      'if you let the oLanConnection go out of scope
      'and be destroyed too soon, the action of the verb
      'may not take...
      '
      wscript.sleep 500


      ' Fin de la procédure
      0