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 :

Aide Script VBS Activation carte reseau lan & Wlan


Sujet :

VBScript

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 9
    Points : 3
    Points
    3
    Par défaut Aide Script VBS Activation carte reseau lan & Wlan
    Salut les programmeurs ; )

    j'ai besoin de l'aide d'une âme charitable car je ne connais rien en programmation et script . j'ai bien essaye un petit peu mais c'est trop compliqué pour mon ptit cerveau : (

    alors je souhaiterai un script qui permet de désactiver/activer automatiquement la carte wifi lorsque un rj45 est branché/débranché du pc.
    je suis passé par quelques entreprises ou ils ont cette fonction sur les pc pour soulager les bornes wifi et je souhaiterai mettre en place cette fonction dans une petite entreprise dont le controleur de domaine tourne sous du 2008 server et ne permet donc pas de creer cette GPO...(je crois que c'est possible qu'a partir d'un win 2012 ou 2016)

    donc j'ai cherché avec mon amis google mais y a pas foule de resultat pour automatiser cette fonction sur un petit domaine.

    j'ai trouvé ce script https://gallery.technet.microsoft.co...contenthttp:// qui semble fonctionner pour certains et pas du tout pour d'autres.

    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
    '========================================================================== 
    ' 
    ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2009 
    ' 
    ' NAME:  
    ' 
    ' AUTHOR: Mohammed Alyafae ,  
    ' DATE  : 9/12/2011 
    ' 
    ' COMMENT: this script disable wireless connection if the LAN is Connected 
    '            and vice versa 
    '========================================================================== 
    On Error Resume Next 
     Dim strComputer 
     Dim objWMIService 
     Dim colLAN 
     Dim objWifi,objLAN 
     Dim state 
     Dim wireStatus 
     Dim wifiStatus 
     
     state="" 
     wireStatus="" 
     wifiStatus="" 
     
     Do While True 
     
     strComputer = "."  
     Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")  
     Set colLAN = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID like 'Local Area Connection' and PhysicalAdapter='True'" ) 
     Set colWiFi=objWMIService.ExecQuery ("Select * From Win32_NetworkAdapter Where NetConnectionID =" & "'" &GetWirlessName & "'" & "and PhysicalAdapter='True' ") 
     
     For Each objWifi In colWiFi 
         If objWifi.Netconnectionstatus=2 Then 
         wifiStatus=True 
         Else 
         wifiStatus=False 
         End If 
     Next 
     
     For Each objLAN in colLAN 
     
     If objLAN.Netconnectionstatus=2 Then 
         wireStatus=True 
         state=False ' this is very importnat variable to determine when to enable or disbale wireless connection    
         Else 
         wireStatus=False 
         End If 
     Next 
     
     
    If True Then 
        If state <>  False Then 
             If wifiStatus = False Then 
             EnableWireless GetWirlessName 
             End If 
        Else  
            If wifiStatus = True Then 
            DisableWireless GetWirlessName 
            End If 
        End If 
     
     End If  
     
     
    state="" 
    wireStatus="" 
    wifiStatus="" 
     
    WScript.Sleep  60000 
     
    Loop 
     
     
    ' Function to get wireless adapter name from the registery 
    Function GetWirlessName  
     
    Dim strKeyPath 
    Dim strComputer 
    Dim objReg 
    Dim arrSubKeys 
    Dim SubKey 
    Dim strValueName 
    Dim dwValue 
    Dim strValue 
    Const HKLM=&H80000002 
     
     
    strKeyPath="SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}" 
    strComputer="." 
     
    Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") 
    objReg.Enumkey HKLM ,strKeyPath,arrSubKeys 
     
    For Each SubKey In arrSubKeys 
        strValueName="MediaSubType" 
        objReg.GetDWORDValue HKLM,strKeyPath & "\" & subkey & "\" & "Connection" ,strValueName,dwValue 
        If dwValue=2 Then 
            strValueName = "Name" 
            objReg.GetStringValue HKLM,strKeyPath & "\" & subkey & "\" & "Connection" ,strValueName,strValue 
            Exit For 
        End If 
    Next 
     
    GetWirlessName=strValue 
     
    End Function 
     
     
     
    ' Subroutine to disable wireless connection  
    Sub DisableWireless (strNetConn) 
     
    Dim oConnections 
    dim objShell 
    Dim objConnections,objConn 
    Dim strDisable 
    Dim objNetwork 
    Dim objDisable 
    Dim objVerb 
     
    Const NETWORK_CONNECTIONS = &H31& 
     
    strDisable = "Disa&ble" 
     
    Set objShell = CreateObject("Shell.Application") 
    Set objConnections = objShell.Namespace(NETWORK_CONNECTIONS) 
     
    For Each objConn In objConnections.Items 
        If objConn.Name = strNetConn Then 
            Set objNetwork = objConn 
            Exit For 
        End If 
    Next 
    Set objDisable = Nothing 
     
    For Each objVerb in objNetwork.verbs 
        If objVerb.name = strDisable Then  
            Set objDisable = objVerb  
            Exit For 
        End If 
     
    Next 
    objDisable.DoIt 
    WScript.Sleep 1000  
    End Sub 
     
    'Function to enable wireless connection , you can combone these two subtoutines into one 
    ' but I prefer to seperate them just for simplicity 
    Sub EnableWireless (strNetConn) 
    Dim oConnections 
    dim objShell 
    Dim objConnections,objConn 
    Dim strEnable 
    Dim objNetwork 
    Dim objEnable 
    Dim objVerb 
     
    Const NETWORK_CONNECTIONS = &H31& 
     
    strEnable = "En&able" 
     
    Set objShell = CreateObject("Shell.Application") 
    Set objConnections = objShell.Namespace(NETWORK_CONNECTIONS) 
     
     
    For Each objConn In objConnections.Items 
    If objConn.Name = strNetConn Then 
        Set objNetwork = objConn 
        Exit For 
    End If 
    Next 
    Set objEnable = Nothing 
     
    ' Enable NIC  
    For Each objVerb in objNetwork.verbs 
        If objVerb.name = strEnable Then  
            Set objEnable = objVerb  
            Exit For 
        End If 
     
    Next 
     
    objEnable.DoIt 
    WScript.Sleep 1000  
    End Sub
    du coup j'ai essaye de faire quelques modif comme indiqué dans les quelques commentaires mais sans plus de résultat.(pour info les pc tournent sous w7 (fr) )

    1°) I check my script encoding to ensure accented characters are correctly interpreted (ANSI from my side)
    2°) I change the WMI request :
    Set colLAN = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID like 'Connexion au réseau local' and PhysicalAdapter='True'" )
    3° I replaced strDisable value by "&Désactiver"
    4° I replaced strEnable by "&Activer"

    All work fine. Thank you Mohammed.
    donc j'en suis arrivé ici

    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
    '==========================================================================
    '==========================================================================
    '
    ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2009
    '
    ' NAME:
    '
    ' AUTHOR: Mohammed Alyafae ,
    ' DATE  : 9/12/2011
    '
    ' COMMENT: this script disable wireless connection if the LAN is Connected
    '            and vice versa
    '==========================================================================
    On Error Resume Next
     Dim strComputer
     Dim objWMIService
     Dim colLAN
     Dim objWifi,objLAN
     Dim state
     Dim wireStatus
     Dim wifiStatus
     
     state=""
     wireStatus=""
     wifiStatus=""
     
     Do While True
     
     strComputer = "."
     Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
     Set colLAN = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID like 'Connexion au réseau local' and PhysicalAdapter='True'" )
     Set colWiFi=objWMIService.ExecQuery ("Select * From Win32_NetworkAdapter Where NetConnectionID =" & "'" &GetWirlessName & "'" & "and PhysicalAdapter='True' ")
     
     For Each objWifi In colWiFi
         If objWifi.Netconnectionstatus=2 Then
         wifiStatus=True
         Else
         wifiStatus=False
         End If
     Next
     
     For Each objLAN in colLAN
     
     If objLAN.Netconnectionstatus=2 Then
         wireStatus=True
         state=False ' this is very importnat variable to determine when to enable or disbale wireless connection
         Else
         wireStatus=False
         End If
     Next
     
     
    If True Then
        If state <>  False Then
             If wifiStatus = False Then
             EnableWireless GetWirlessName
             End If
        Else
            If wifiStatus = True Then
            DisableWireless GetWirlessName
            End If
        End If
     
     End If
     
     
    state=""
    wireStatus=""
    wifiStatus=""
     
    WScript.Sleep  60000
     
    Loop
     
     
    ' Function to get wireless adapter name from the registery
    Function GetWirlessName
     
    Dim strKeyPath
    Dim strComputer
    Dim objReg
    Dim arrSubKeys
    Dim SubKey
    Dim strValueName
    Dim dwValue
    Dim strValue
    Const HKLM=&H80000002
     
     
    strKeyPath="SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"
    strComputer="."
     
    Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    objReg.Enumkey HKLM ,strKeyPath,arrSubKeys
     
    For Each SubKey In arrSubKeys
        strValueName="MediaSubType"
        objReg.GetDWORDValue HKLM,strKeyPath & "\" & subkey & "\" & "Connection" ,strValueName,dwValue
        If dwValue=2 Then
            strValueName = "Name"
            objReg.GetStringValue HKLM,strKeyPath & "\" & subkey & "\" & "Connection" ,strValueName,strValue
            Exit For
        End If
    Next
     
    GetWirlessName=strValue
     
    End Function
     
     
     
    ' Subroutine to disable wireless connection
    Sub DisableWireless (strNetConn)
     
    Dim oConnections
    dim objShell
    Dim objConnections,objConn
    Dim strDisable
    Dim objNetwork
    Dim objDisable
    Dim objVerb
     
    Const NETWORK_CONNECTIONS = &H31&
     
    strDisable = "&Désactiver"
     
    Set objShell = CreateObject("Shell.Application")
    Set objConnections = objShell.Namespace(NETWORK_CONNECTIONS)
     
    For Each objConn In objConnections.Items
        If objConn.Name = strNetConn Then
            Set objNetwork = objConn
            Exit For
        End If
    Next
    Set objDisable = Nothing
     
    For Each objVerb in objNetwork.verbs
        If objVerb.name = strDisable Then
            Set objDisable = objVerb
            Exit For
        End If
     
    Next
    objDisable.DoIt
    WScript.Sleep 1000
    End Sub
     
    'Function to enable wireless connection , you can combone these two subtoutines into one
    ' but I prefer to seperate them just for simplicity
    Sub EnableWireless (strNetConn)
    Dim oConnections
    dim objShell
    Dim objConnections,objConn
    Dim strEnable
    Dim objNetwork
    Dim objEnable
    Dim objVerb
     
    Const NETWORK_CONNECTIONS = &H31&
     
    strEnable = "&Activer"
     
    Set objShell = CreateObject("Shell.Application")
    Set objConnections = objShell.Namespace(NETWORK_CONNECTIONS)
     
     
    For Each objConn In objConnections.Items
    If objConn.Name = strNetConn Then
        Set objNetwork = objConn
        Exit For
    End If
    Next
    Set objEnable = Nothing
     
    ' Enable NIC
    For Each objVerb in objNetwork.verbs
        If objVerb.name = strEnable Then
            Set objEnable = objVerb
            Exit For
        End If
     
    Next
     
    objEnable.DoIt
    WScript.Sleep 1000
    End Sub

    quelqu'un veut bien m'aider un peu ou m'aiguiller sur la direction a prendre ?

    grand merci d'avance messieurs

  2. #2
    Membre confirmé Avatar de Superzest 76
    Homme Profil pro
    Automaticien
    Inscrit en
    Septembre 2018
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Automaticien
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2018
    Messages : 144
    Points : 519
    Points
    519
    Par défaut
    Salut a toi !
    Tout tes OS sont en 32 bit ? un début de réponse se trouve peut être la ?
    “Cookie : Anciennement petit gâteau sucré, qu’on acceptait avec plaisir. Aujourd’hui : petit fichier informatique drôlement salé, qu’il faut refuser avec véhémence.”
    N'oubliez pas le si un message vous à aider a résoudre votre problème !

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 9
    Points : 3
    Points
    3
    Par défaut
    la majorité doit être en 64bits. pourquoi ? il n'est pas indiqué par l'auteur de ce script que celui si ne fonctionne que sur du 32 ou que sur du 64 bits. ce serait le cas selon toi ?

    j'ai vraiment essayé de comprendre le code mais bien trop compliqué pour moi. mon experience s'arrete à quelques scripts avec autoIt ou php

  4. #4
    Membre confirmé Avatar de Superzest 76
    Homme Profil pro
    Automaticien
    Inscrit en
    Septembre 2018
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Automaticien
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2018
    Messages : 144
    Points : 519
    Points
    519
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Set colLAN = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID like 'Local Area Connection' and PhysicalAdapter='True'" ) 
     Set colWiFi=objWMIService.ExecQuery ("Select * From Win32_NetworkAdapter Where NetConnectionID =" & "'" &GetWirlessName & "'" & "and PhysicalAdapter='True' ")
    Pour moi tu doit adapter ce bout de code pour correspondre a win64
    Je suis désoler mais mes connaissance en Windows me permette de savoir que l'erreur viens de la pas de la corriger.

    J’espère qu'un confrère plus éclairer viendra t'aider.


    Bonne recherche
    “Cookie : Anciennement petit gâteau sucré, qu’on acceptait avec plaisir. Aujourd’hui : petit fichier informatique drôlement salé, qu’il faut refuser avec véhémence.”
    N'oubliez pas le si un message vous à aider a résoudre votre problème !

Discussions similaires

  1. Réponses: 1
    Dernier message: 20/05/2009, 17h33
  2. Aide pour réaliser un petit script vbs
    Par gogéta91 dans le forum VBScript
    Réponses: 1
    Dernier message: 04/08/2008, 13h33
  3. desactiver activer carte reseau
    Par lezurp dans le forum C#
    Réponses: 14
    Dernier message: 19/03/2008, 15h28
  4. Aide en script VBS
    Par scova dans le forum Windows
    Réponses: 1
    Dernier message: 01/11/2007, 22h04
  5. script vbs : besoin d'aide
    Par 7alex dans le forum VBScript
    Réponses: 13
    Dernier message: 10/01/2006, 15h00

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