IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Désactiver une conection réseau


Sujet :

VBScript

  1. #1
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut Désactiver une conection réseau
    Bonjour, est il possible en vbs de désactiver une connection réseau et en activer une autre ?

    Si oui, comment ?

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    Voir

    Où trouver l'aide en ligne pour VBScript ?

    et dans l'aide en ligne :

    Code Aide en ligne : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Exemple
    
     Le code suivant supprime le lecteur "E" logique.
     [VBScript] Dim WshNetwork
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.RemoveNetworkDrive "E:"


    pour la connection :

    http://vb.developpez.com/faqvbs/?pag...#vbsmapnetwork

  3. #3
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    bpnjour rt merci bbil

    Ce n'est pas un lecteur réseau mais la connection que je veut désactiver

  4. #4
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetCards = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration " & "Where IPEnabled = True")
    For Each objNetCard in colNetCards
        objNetCard.ReleaseDHCPLease()
    Next
    Et si tu veux le faire sur une carte précise et non sur toute car ayant une IP, tu peux utiliser les propriété de NetworkAdapterConfiguration.
    Désolé c trop long pour que je traduise tout, mais si tu lances l'exemple donné à la fin de la page, tu pourras déterminer quelle propriété renseigne quoi comme information
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  5. #5
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    salut ced600

    merci mais je voudrai désactiver la connection par son non, par exemple:
    Connexion au réseau local

  6. #6
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Si je me souviens une des propriétés de NetworkAdapterConfiguration te pertmet d'avoir le nom de la connexion (deuxième lien).
    Dans le code que je t'ai passé tu as une boucle.
    Dedans tu fais un test sur le nom de la connexion (objNetCard.NomDeLaBonnePropriété) pour savoir si elle est égal au nom genre "Connexion au réseau local". Et si c'est le cas tu la désactive par objNetCard.ReleaseDHCPLease().
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  7. #7
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Comme ca ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetCards = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration " & "Where IPEnabled = True")
    For Each objNetCard in colNetCards
     if NetworkAdapterConfiguration = "Connexion au réseau local" then objNetCard.ReleaseDHCPLease()
    Next
    si je rajoute:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     msgbox NetworkAdapterConfiguration
    le msgbox reste vide

    Je ne trouve pas la propriété qui donne le nom de la connection

  8. #8
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Citation Envoyé par koKoTis Voir le message
    Je ne trouve pas la propriété qui donne le nom de la connection
    Le nom de la bonne propriété

    Je ne me souviens plus de laquelle, mais sur le lien tu a un exemple de script qui t'affichera tout le contenu des propriétés de l'objet NetworkAdapterConfiguration.

    Tu as aussi dans les contribution, ma contribution sur WMICodeCreator (je t'en avais déjà parlé) qui te donneras les explications sur cette classe et ses propriétés.

    NetworkAdapterConfiguration est un objet tu ne peux pas l'utiliser comme tu l'as fait. Par contre tu peux faire appels à ses méthodes et ses propriétés.

    Du fait de la façon dont on doit récupérer un lien vers cette objet dans une collection, pour pouvoir l'utiliser, tu doit utiliser : objNetCard
    D'où ma phrase :
    objNetCard.NomDeLaBonnePropriété
    Si je prend en exemple DNSHostName, met dans la boucle :
    msgbox objNetCard.DNSHostName et cela t'affichera le nom du PC local.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  9. #9
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Citation Envoyé par ced600 Voir le message
    Si je prend en exemple DNSHostName, met dans la boucle :
    msgbox objNetCard.DNSHostName et cela t'affichera le nom du PC local.
    Je vien justement de la comprendre, mais dans le script je ne trouve pas la propriéte du noml de la connection, j'ai exécuter le script il y a le nom de la carte mais pas de la connection

  10. #10
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    J'ai regardé aussi et il semble que je me trompe, on n'a que les info de la carte, et pas le nom de la connexion.

    D'ailleurs je crois me souvenir que c t le problème de quelqu'un sur une des discussions du fofo.

    J'ai regardé d'autre objet WMI est j'ai pas trouvé l'info que tu recherches.

    Tu as toujours Ipconfig /Release pour désactiver la connection internet (et renew pour la réactiver), mais si tu es sur un réseau avec DHCP (c en général le cas), je me demande s'il ne peux pas te refournir une @IP un certain temps après ton release. Car tu ne désactive pas en soit mais tu supprimez ton adresse IP.

    Peut être avec NetSH c'est faisable mais je ne sais pas comment.

    Sinon il y a un petit prog fournis par MS pour désactiver une carte réseau à l'aide du nom de l'interface :
    La page de téléchargement et d'aide de l'outil en français.

    Bref c pas encore vraiment cela, mais regarde au ce prog (devcon) et vois s'il peut faire ce que tu souhaites.

    Edit : En dos regarde du coté de : Netsh Interface Delete Name = "Local Area Connection"
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  11. #11
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    je veut bien utiliser une commande dos, mais pas une commande externe

    par contre, tu dit que ce ne fait que supprimer l'ip, donc la cponnection elle même n'est pas désactivé a lor ?
    c'est pareil avec le VBS ?

  12. #12
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Citation Envoyé par koKoTis Voir le message
    je veut bien utiliser une commande dos, mais pas une commande externe

    par contre, tu dit que ce ne fait que supprimer l'ip, donc la cponnection elle même n'est pas désactivé a lor ?
    c'est pareil avec le VBS ?
    Possible.

    Edit : En dos regarde du coté de : Netsh Interface Delete Name = "Local Area Connection"
    -> je l'ai ajouté après ton message.
    Recherche sur le net avant d'essayer.
    Soit cela la désactive, soit cela la supprime, faudrait quand même pas la supprimer.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  13. #13
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    il na parle pas de cette syntaxe sur le net

  14. #14
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Alors il faut faire une recherche sur des tutoriaux de netsh ou du moins pour netsh interface
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  15. #15
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    ok je vai voir ca merci encore

  16. #16
    Membre éprouvé
    Avatar de maxim_um
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    895
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 895
    Points : 1 018
    Points
    1 018
    Par défaut
    Cadeau,

    Fichier : NTNetConnection.vbs
    Le Lien: http://www.mediafire.com/download.php?eadmsazwysy

    Somme MD5 de l'archive NTNetConnection.zip : f46f0dd086af1884ca1bf13ce12dd773

    enjoy

  17. #17
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Citation Envoyé par maxim_um Voir le message
    Cadeau,

    Fichier : NTNetConnection.vbs
    Le Lien: http://www.mediafire.com/download.php?eadmsazwysy

    Somme MD5 de l'archive NTNetConnection.zip : f46f0dd086af1884ca1bf13ce12dd773

    enjoy

    Bonjour et merci

    mais quand j'ajoute ton script ici, ca bug:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    <html>
    <head>
    <title>ActiveDesactiveComm</title>
    <HTA:APPLICATION
         ID="ActiveDesactiveComm"
         APPLICATIONNAME="ActiveDesactiveComm"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="normal"
         CAPTION="yes"
    >
    </head>
    <style>
    BODY
    {
       background-color: buttonface;
       font-family: Helvetica;
       font-size: 10pt;
       margin-top: 10px;
       margin-left: 20px;
       margin-right: 20px;
       margin-bottom: 10px;
    }
     
    .button
    {
       font-family: Helvetica;
       font-size: 8pt;
    }
    </style>
     
    <SCRIPT Language="VBScript">
    Sub Window_Onload
        On error resume next
        ListView1.font = "arial"
        ListView1.View = 3
        ListView1.GridLines = True
        ListView1.ColumnHeaders.Add , , "Name", 200
        ListView1.ColumnHeaders.Add , , "IsLANConnection", 100
        ListView1.ColumnHeaders.Add , , "GUID", 150
        ListView1.ColumnHeaders.Add , , "PhoneBookPath", 300
     
     
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
        For Each objItem in colItems
            intHorizontal = objItem.ScreenWidth
            intVertical = objItem.ScreenHeight
        Next
     
        XPos = 800
        YPos = 390
     
        intLeft = (intHorizontal - XPos) / 2
        intTop = (intVertical - YPos) / 2
     
        self.ResizeTo Xpos,YPos
        window.moveTo intLeft, intTop
        strComputer = "."
        Set objWMIService = GetObject _
        ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
        Set colItems = objWMIService.ExecQuery("Select * from HNet_Connection")
        For Each objItem in colItems
            Set itmx = ListView1.ListItems.Add(, ,objItem.Name)
            If objItem.IsLANConnection = True Then
               itmX.SubItems(1) = "Enabled"
            Else
               itmX.SubItems(1) = "Disabled"
            End If
            itmX.SubItems(2) = objItem.GUID
            itmX.SubItems(3) = objItem.PhoneBookPath
        Next
     
    End Sub
     
    Sub Refresh
     
        ListView1.ListItems.Clear()
        Window_Onload
     
    End Sub
     
    Sub ListView1_ColumnClick(ColumnHeader)
    	With ListView1
    		.Sorted = False
    		.SortKey = ColumnHeader.Index - 1
    		If .SortOrder = 0 Then
    			.SortOrder = 1
    		Else
    			.SortOrder = 0
    		End If
    		.Sorted = True
    	End With
    End Sub
     
    Sub ListView1_Click
     
     
        If ListView1.SelectedItem.SubItems(1) = "Disabled" Then
           strAction = "enable"
        Else
           strAction = "disable"
        End if
        Quest = MsgBox("The connexion " & ListView1.SelectedItem & " is actually " & ListView1.SelectedItem.SubItems(1) & ", do you want to " &  strAction & " it ?",vbQuestion + vbYesNoCancel + vbApplicationModal + 0,"Action")
     
        If Quest = VbYes Then
           If strAction = "enable" Then
    Option Explicit
    Dim sConnName, sNetFldr
    Dim sConnect, sDisconnect
    Dim sMsgD, sMsgNf
    Dim bEnabled
    Dim oVerb, oConnectVerb, oDisconnectVerb, oIConnection,oNetConn, oFldrItem
     
    sConnName = ListView1.SelectedItem 
    sNetFldr = "Connexions réseau"
    sConnect = "&Activer"
    sDisconnect = "&Désactiver"
    sMsgD = "Désactivation en cours ..."
    sMsgNf = "impossible de trouver '"
     
    bEnabled = True
    For Each oFldrItem in CreateObject("Shell.Application").Namespace(3).Items
      If oFldrItem.Name = sNetFldr Then
        Set oNetConn = oFldrItem.GetFolder
        Exit For
      End If
    next
     
    If Not IsObject(oNetConn) Then
      MsgBox sMsgNf & sNetFldr & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oFldrItem in oNetConn.items
      If LCase(oFldrItem.Name) = LCase(sConnName) Then
        Set oIConnection = oFldrItem
        Exit For
      End If
    next
     
    If Not IsObject(oIConnection) Then
      MsgBox sMsgNf & sConnName & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oVerb in oIConnection.verbs
      If oVerb.Name = sConnect Then 
        Set oConnectVerb = oVerb 
        bEnabled = False
      End If
      If oVerb.Name = sDisconnect Then 
        Set oDisconnectVerb = oVerb 
      End If
    Next
     
    If bEnabled Then
      oDisconnectVerb.DoIt
      CreateObject("WScript.Shell").Popup sMsgD & vbTab, 3, sConnName , vbInformation 
    Else
      oConnectVerb.DoIt
    End If
     
    WScript.Sleep 2000        Else
     
    Option Explicit
    Dim sConnName, sNetFldr
    Dim sConnect, sDisconnect
    Dim sMsgD, sMsgNf
    Dim bEnabled
    Dim oVerb, oConnectVerb, oDisconnectVerb, oIConnection,oNetConn, oFldrItem
     
    sConnName = ListView1.SelectedItem 
    sNetFldr = "Connexions réseau"
    sConnect = "&Activer"
    sDisconnect = "&Désactiver"
    sMsgD = "Désactivation en cours ..."
    sMsgNf = "impossible de trouver '"
     
    bEnabled = True
    For Each oFldrItem in CreateObject("Shell.Application").Namespace(3).Items
      If oFldrItem.Name = sNetFldr Then
        Set oNetConn = oFldrItem.GetFolder
        Exit For
      End If
    next
     
    If Not IsObject(oNetConn) Then
      MsgBox sMsgNf & sNetFldr & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oFldrItem in oNetConn.items
      If LCase(oFldrItem.Name) = LCase(sConnName) Then
        Set oIConnection = oFldrItem
        Exit For
      End If
    next
     
    If Not IsObject(oIConnection) Then
      MsgBox sMsgNf & sConnName & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oVerb in oIConnection.verbs
      If oVerb.Name = sConnect Then 
        Set oConnectVerb = oVerb 
        bEnabled = False
      End If
      If oVerb.Name = sDisconnect Then 
        Set oDisconnectVerb = oVerb 
      End If
    Next
     
    If bEnabled Then
      oDisconnectVerb.DoIt
      CreateObject("WScript.Shell").Popup sMsgD & vbTab, 3, sConnName , vbInformation 
    Else
      oConnectVerb.DoIt
    End If
     
    WScript.Sleep 2000  
           End If
           Refresh
        Else
           Msgbox "Command aborted."
        End If
     
     
    End Sub
     
     
    Sub Quitter
     
        self.Close()
     
    End sub
     
    </SCRIPT>
     
    <body bgcolor="buttonface">
     
    <table WIDTH="100%" BORDER=1>
    <td VALIGN=TOP WIDTH="18%" COLUMN=1>
     
    <td width="750" height="240" style="border: 1px solid #C0C0C0">
    <OBJECT ID="ListView1" style="font-size:8pt" WIDTH=750 HEIGHT=250 CLASSID="CLSID:BDD1F04B-858B-11D1-B16A-00C0F0283628">
    		        <PARAM NAME="SortKey" VALUE="0">
    		        <PARAM NAME="View" VALUE="3">
    		        <PARAM NAME="Arrange" VALUE="0">
    		        <PARAM NAME="LabelEdit" VALUE="1">
    		        <PARAM NAME="SortOrder" VALUE="0">
    		        <PARAM NAME="Sorted" VALUE="-1">
    		        <PARAM NAME="MultiSelect" VALUE="0">
    		        <PARAM NAME="LabelWrap" VALUE="-1">
    		        <PARAM NAME="HideSelection" VALUE="0">
    		        <PARAM NAME="HideColumnHeaders" VALUE="0">
    		        <PARAM NAME="OLEDragMode" VALUE="0">
    		        <PARAM NAME="OLEDropMode" VALUE="0">
    		        <PARAM NAME="AllowReorder" VALUE="-1">
    		        <PARAM NAME="Checkboxes" VALUE="0">
    		        <PARAM NAME="FlatScrollBar" VALUE="0">
    		        <PARAM NAME="FullRowSelect" VALUE="-1">
    		        <PARAM NAME="GridLines" VALUE="-1">
    		        <PARAM NAME="HotTracking" VALUE="0">
    		        <PARAM NAME="HoverSelection" VALUE="0">
    		        <PARAM NAME="PictureAlignment" VALUE="0">
    	                <PARAM NAME="TextBackground" VALUE="0">
                            <PARAM NAME="ForeColor" VALUE="-2147483640">
    	                <PARAM NAME="BackColor" VALUE="-2147483624">
    		        <PARAM NAME="BorderStyle" VALUE="0">
    		        <PARAM NAME="Appearance" VALUE="0">
    		        <PARAM NAME="MousePointer" VALUE="0">
    		        <PARAM NAME="Enabled" VALUE="1">
    		        <PARAM NAME="NumItems" VALUE="0">
    	   		<param name="OLEDragMode" value="0">
    			<param name="OLEDropMode" value="0">
    </OBJECT>
     
     
    </Table>
    </p>
     
    <fieldset>
    <br>
    <Center>
    <input id=Quitbutton  class="button" type="button" value="   Quit   " name="Quitter_Button"  onClick="Quitter">
    </center>
    <br>
    </fieldset>
    </body>
    </html>

  18. #18
    Membre éprouvé
    Avatar de maxim_um
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    895
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 895
    Points : 1 018
    Points
    1 018
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
     
    <html>
    <head>
    <title>ActiveDesactiveComm</title>
    <HTA:APPLICATION
         ID="ActiveDesactiveComm"
         APPLICATIONNAME="ActiveDesactiveComm"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="normal"
         CAPTION="yes"
    >
    </head>
    <style>
    BODY
    {
       background-color: buttonface;
       font-family: Helvetica;
       font-size: 10pt;
       margin-top: 10px;
       margin-left: 20px;
       margin-right: 20px;
       margin-bottom: 10px;
    }
     
    .button
    {
       font-family: Helvetica;
       font-size: 8pt;
    }
    </style>
     
    <SCRIPT Language="VBScript">
    Sub Window_Onload
        On error resume next
        ListView1.font = "arial"
        ListView1.View = 3
        ListView1.GridLines = True
        ListView1.ColumnHeaders.Add , , "Name", 200
        ListView1.ColumnHeaders.Add , , "IsLANConnection", 100
        ListView1.ColumnHeaders.Add , , "GUID", 150
        ListView1.ColumnHeaders.Add , , "PhoneBookPath", 300
     
     
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
        For Each objItem in colItems
            intHorizontal = objItem.ScreenWidth
            intVertical = objItem.ScreenHeight
        Next
     
        XPos = 800
        YPos = 390
     
        intLeft = (intHorizontal - XPos) / 2
        intTop = (intVertical - YPos) / 2
     
        self.ResizeTo Xpos,YPos
        window.moveTo intLeft, intTop
        strComputer = "."
        Set objWMIService = GetObject _
        ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
        Set colItems = objWMIService.ExecQuery("Select * from HNet_Connection")
        For Each objItem in colItems
            Set itmx = ListView1.ListItems.Add(, ,objItem.Name)
            If objItem.IsLANConnection = True Then
               itmX.SubItems(1) = "Enabled"
            Else
               itmX.SubItems(1) = "Disabled"
            End If
            itmX.SubItems(2) = objItem.GUID
            itmX.SubItems(3) = objItem.PhoneBookPath
        Next
     
    End Sub
     
    Sub Refresh
     
        ListView1.ListItems.Clear()
        Window_Onload
     
    End Sub
     
    Sub ListView1_ColumnClick(ColumnHeader)
    	With ListView1
    		.Sorted = False
    		.SortKey = ColumnHeader.Index - 1
    		If .SortOrder = 0 Then
    			.SortOrder = 1
    		Else
    			.SortOrder = 0
    		End If
    		.Sorted = True
    	End With
    End Sub
     
    Sub ListView1_Click
     
    Dim sConnName, sNetFldr
    Dim sConnect, sDisconnect
    Dim sMsgD, sMsgNf
    Dim bEnabled
    Dim oVerb, oConnectVerb, oDisconnectVerb, oIConnection,oNetConn, oFldrItem
    bEnabled = True
    sNetFldr = "Connexions réseau"
    sConnect = "&Activer"
    sDisconnect = "&Désactiver"
    sMsgD = "Désactivation en cours ..."
    sMsgNf = "impossible de trouver '" 
     
     
        If ListView1.SelectedItem.SubItems(1) = "Disabled" Then
           strAction = "enable"
        Else
           strAction = "disable"
        End if
        Quest = MsgBox("The connexion " & ListView1.SelectedItem & " is actually " & ListView1.SelectedItem.SubItems(1) & ", do you want to " &  strAction & " it ?",vbQuestion + vbYesNoCancel + vbApplicationModal + 0,"Action")
     
        If Quest = VbYes Then
           If strAction = "enable" Then
     
     
    sConnName = ListView1.SelectedItem 
    For Each oFldrItem in CreateObject("Shell.Application").Namespace(3).Items
      If oFldrItem.Name = sNetFldr Then
        Set oNetConn = oFldrItem.GetFolder
        Exit For
      End If
    next
     
    If Not IsObject(oNetConn) Then
      MsgBox sMsgNf & sNetFldr & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oFldrItem in oNetConn.items
      If LCase(oFldrItem.Name) = LCase(sConnName) Then
        Set oIConnection = oFldrItem
        Exit For
      End If
    next
     
    If Not IsObject(oIConnection) Then
      MsgBox sMsgNf & sConnName & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oVerb in oIConnection.verbs
      If oVerb.Name = sConnect Then 
        Set oConnectVerb = oVerb 
        bEnabled = False
      End If
      If oVerb.Name = sDisconnect Then 
        Set oDisconnectVerb = oVerb 
      End If
    Next
     
    If bEnabled Then
      oDisconnectVerb.DoIt
      CreateObject("WScript.Shell").Popup sMsgD & vbTab, 3, sConnName , vbInformation 
    Else
      oConnectVerb.DoIt
    End If
     
     
     
    Else
     
    sConnName = ListView1.SelectedItem 
    For Each oFldrItem in CreateObject("Shell.Application").Namespace(3).Items
      If oFldrItem.Name = sNetFldr Then
        Set oNetConn = oFldrItem.GetFolder
        Exit For
      End If
    next
     
    If Not IsObject(oNetConn) Then
      MsgBox sMsgNf & sNetFldr & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oFldrItem in oNetConn.items
      If LCase(oFldrItem.Name) = LCase(sConnName) Then
        Set oIConnection = oFldrItem
        Exit For
      End If
    next
     
    If Not IsObject(oIConnection) Then
      MsgBox sMsgNf & sConnName & "'",48,"NTNetConnection"
      WScript.Quit
    End If
     
    For Each oVerb in oIConnection.verbs
      If oVerb.Name = sConnect Then 
        Set oConnectVerb = oVerb 
        bEnabled = False
      End If
      If oVerb.Name = sDisconnect Then 
        Set oDisconnectVerb = oVerb 
      End If
    Next
     
    If bEnabled Then
      oDisconnectVerb.DoIt
      CreateObject("WScript.Shell").Popup sMsgD & vbTab, 3, sConnName , vbInformation 
    Else
      oConnectVerb.DoIt
    End If
     
           End If
           Refresh
        Else
           Msgbox "Command aborted."
        End If
     
     
    End Sub
     
     
    Sub Quitter
     
        self.Close()
     
    End sub
     
    </SCRIPT>
     
    <body bgcolor="buttonface">
     
    <table WIDTH="100%" BORDER=1>
    <td VALIGN=TOP WIDTH="18%" COLUMN=1>
     
    <td width="750" height="240" style="border: 1px solid #C0C0C0">
    <OBJECT ID="ListView1" style="font-size:8pt" WIDTH=750 HEIGHT=250 CLASSID="CLSID:BDD1F04B-858B-11D1-B16A-00C0F0283628">
    		        <PARAM NAME="SortKey" VALUE="0">
    		        <PARAM NAME="View" VALUE="3">
    		        <PARAM NAME="Arrange" VALUE="0">
    		        <PARAM NAME="LabelEdit" VALUE="1">
    		        <PARAM NAME="SortOrder" VALUE="0">
    		        <PARAM NAME="Sorted" VALUE="-1">
    		        <PARAM NAME="MultiSelect" VALUE="0">
    		        <PARAM NAME="LabelWrap" VALUE="-1">
    		        <PARAM NAME="HideSelection" VALUE="0">
    		        <PARAM NAME="HideColumnHeaders" VALUE="0">
    		        <PARAM NAME="OLEDragMode" VALUE="0">
    		        <PARAM NAME="OLEDropMode" VALUE="0">
    		        <PARAM NAME="AllowReorder" VALUE="-1">
    		        <PARAM NAME="Checkboxes" VALUE="0">
    		        <PARAM NAME="FlatScrollBar" VALUE="0">
    		        <PARAM NAME="FullRowSelect" VALUE="-1">
    		        <PARAM NAME="GridLines" VALUE="-1">
    		        <PARAM NAME="HotTracking" VALUE="0">
    		        <PARAM NAME="HoverSelection" VALUE="0">
    		        <PARAM NAME="PictureAlignment" VALUE="0">
    	                <PARAM NAME="TextBackground" VALUE="0">
                            <PARAM NAME="ForeColor" VALUE="-2147483640">
    	                <PARAM NAME="BackColor" VALUE="-2147483624">
    		        <PARAM NAME="BorderStyle" VALUE="0">
    		        <PARAM NAME="Appearance" VALUE="0">
    		        <PARAM NAME="MousePointer" VALUE="0">
    		        <PARAM NAME="Enabled" VALUE="1">
    		        <PARAM NAME="NumItems" VALUE="0">
    	   		<param name="OLEDragMode" value="0">
    			<param name="OLEDropMode" value="0">
    </OBJECT>
     
     
    </Table>
    </p>
     
    <fieldset>
    <br>
    <Center>
    <input id=Quitbutton  class="button" type="button" value="   Quit   " name="Quitter_Button"  onClick="Quitter">
    </center>
    <br>
    </fieldset>
    </body>
    </html>
    je ne peux pas le tester ton script parce que je ne dispose pas du composant ListView CLSID:BDD1F04B-858B-11D1-B16A-00C0F0283628. Le numéro ne doit probablement pas correspondre avec ma version de mscomctl.ocx

    J’ai cependant apporté les quelques corrections nécessaires à ton script pour que ça ne te génère plus d'erreurs.

  19. #19
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    merci ca marche parfaitement bien
    merci beaucoup

  20. #20
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Je ne savais pas que l'on pouvait faire cela.
    Parcourir les connexion réseau comme un répertoire.
    Récupérer la bonne connexion.
    Et utiliser verbs pour avoir la liste des actions possibles.
    Et une fois positionner sur l'action, l'exécuter.

    Je suppose que c'est faisable pour tout autre chose que les connexions réseau ?
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. activer/désactiver une carte réseau
    Par jehrikhan dans le forum Windows
    Réponses: 1
    Dernier message: 30/07/2008, 16h32
  2. Activer ou désactiver une connexion réseau et wifi
    Par koKoTis dans le forum Scripts/Batch
    Réponses: 2
    Dernier message: 10/10/2007, 23h49
  3. Activer / Désactiver une connexion réseau
    Par Neilos dans le forum Windows
    Réponses: 6
    Dernier message: 25/09/2006, 14h42
  4. Réponses: 5
    Dernier message: 22/12/2004, 16h50
  5. Connaître l'état d'une connexion réseau
    Par SteelBox dans le forum Windows
    Réponses: 8
    Dernier message: 29/07/2004, 12h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo