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

VB 6 et antérieur Discussion :

Bouton appel fonction par rapport à résultat


Sujet :

VB 6 et antérieur

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut Bouton appel fonction par rapport à résultat
    Bonjour à tous.

    J'essaye de faire un petit exe en VB 6 pour changer mes paramètres de connexions réseau. L'application m'éviterait de modifier l'adresse IP à la main.

    Fonctionnement : Quand l'application est lançée, elle détecte si je suis en configuration "skwat" ou "bureau".

    Un bouton nommé "change_button" est sur ma form principale.
    J'ai créé les 2 fonctions "writeskwat_reg" et "writebureau_reg". Elles écrivent leurs contenus dans la base de registre.
    Une fonction del_reg() pour préalablement effacer les précédentes données ( car plus propre ).

    Je bloque : quand je clique sur mon bouton (change_button), en fonction du
    résultat "skwat" ou "bureau", je n'arrive pas à renvoyer la bonne fonction !

    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
    Private Sub Change_button_Click()
    Dim WshShell
     
    Set WshShell = CreateObject("WScript.Shell")
    empl = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
     
        If empl = "skwat" Then
        Call del_reg    
        Call writeskwat_reg
        ElseIf empl = "bureau" Then
        Call del_reg
        Call writebureau_reg
        Else
        End If
     
    End Sub
    Mon code complet :
    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
    Public Function writeskwat_reg()
    Dim WshShell
     
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon", "skwat"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\UseZeroBroadcast", "00000000", "REG_DWORD"
    ...
     
    End Function
     
    Public Function writebureau_reg()
    Dim WshShell
     
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon", "bureau"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\UseZeroBroadcast", "00000000", "REG_DWORD"
    ...
     
    End Function
     
    Public Sub read_Click()
    Dim WshShell
     
    Set WshShell = CreateObject("WScript.Shell")
    MsgBox WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
     
    End Sub
     
    Public Function del_reg()
    Dim WshShell
     
    Set WshShell = CreateObject("WScript.Shell")
    On Error Resume Next
    WshShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon"
    WshShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\UseZeroBroadcast"
    ...
     
     
    End Function
     
    Public Sub Form_load()
    Dim WshShell
     
    Set WshShell = CreateObject("WScript.Shell")
    empl = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
     
    If empl = "skwat" Then
           Mode.Caption = "Vous êtes actuellement configuré en mode Skwat"
           Bascule_mode.Caption = "Basculer en mode Bureau"
           AdresseIP.Caption = "Adresse IP : 192.168.20.69"
       ElseIf empl = "bureau" Then
           Mode.Caption = "Vous êtes actuellement configuré en mode Bureau"
           Bascule_mode.Caption = "Basculer en mode Skwat"
           AdresseIP.Caption = "Adresse IP : automatique"
       Else: Mode.Caption = "Configuration est différente des modes proposés par cette application"
             Bascule_mode.Caption = ""
       End If
     
    End Sub
     
    Private Sub Change_button_Click()
    Dim WshShell
     
    Set WshShell = CreateObject("WScript.Shell")
    empl = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
     
        If empl = "skwat" Then
        Call del_reg
        Call writeskwat_reg    
        ElseIf empl = "bureau" Then
        Call del_reg
        Call writebureau_reg
        Else
        End If
     
    End Sub
    En fait, je veux dans les deux cas effacer les données du registre et quand c'est terminé, lancer la fonction ( en fonction de la lecture de la clé "ModeCon" )

    Donc voila si des personnes peuvent m'éclairer, j'ai cherché dans des bouquins, des forums, essayé tout ça et çà ne fonctionne pas.

    Mon code n'est pas optimisé pour l'instant, ce n'est pas une proposition de code source mais juste un besoin d'aide, merci pour votre indulgence.

    Après si vous avez d'autres conseils sur ce que j'ai déjà écrit, je suis preneur et ça servirai peut-être à d'autre personne qui, comme moi, son noob en VB.

    Merci à bientôt

  2. #2
    Membre Expert Avatar de OhMonBato
    Homme Profil pro
    Inscrit en
    Mars 2007
    Messages
    2 660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 2 660
    Par défaut
    Bonjour,

    peux tu préciser ce qui ne marche pas exactement ? As tu vérifié le contenu de ta variable "empl" ? Vaut-elle bien EXACTEMENT "skwat" ou "bureau" (Les majuscules/minuscules sont importantes).

    Pour vérifier la valeur de ta variable,tu peux mettre un point d'arrêt dans ton code ou affichier la valeur de ta variable avec une messagebox, par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    empl = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
    msgbox skwat
    If empl = "skwat" Then

  3. #3
    Invité
    Invité(e)
    Par défaut
    Salut Ohmonbato

    Merci pour ta réponse.

    En fait, j'avais testé le retour de "empl" avec un msgbox. Il me renvoi bien "skwat" ou "bureau".

    J'ai modifié mon code depuis tout à l'heure : les 2 fonctions "writeskwat_reg" et "writebureau_reg" ont disparus, je les ai incluses directement dans le "change_button_click".

    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
    Public Sub read_Click()
    Dim ReadShell
     
    Set ReadShell = CreateObject("WScript.Shell")
    MsgBox ReadShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
     
    End Sub
     
    Public Sub Form_load()
    Dim DonneeShell
     
    Set DonneeShell = CreateObject("WScript.Shell")
    empl = DonneeShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
     
    If empl = "skwat" Then
           Mode.Caption = "Vous êtes actuellement configuré en mode Skwat"
           Bascule_mode.Caption = "Basculer en mode Bureau"
           AdresseIP.Caption = "Adresse IP : 192.168.20.69"
       ElseIf empl = "bureau" Then
           Mode.Caption = "Vous êtes actuellement configuré en mode Bureau"
           Bascule_mode.Caption = "Basculer en mode Skwat"
           AdresseIP.Caption = "Adresse IP : automatique"
       Else: Mode.Caption = "Configuration est différente des modes proposés par cette application"
             Bascule_mode.Caption = ""
             Change_button.Visible = False
       End If
     
    End Sub
     
    Public Sub Change_button_Click()
    Dim DonneeShell
     
    Set DonneeShell = CreateObject("WScript.Shell")
    empl = DonneeShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon")
     
        If empl = "bureau" Then
        Dim DelShell
        Dim WSkwatShell
     
        Set DelShell = CreateObject("WScript.Shell")
        On Error Resume Next
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\UseZeroBroadcast"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDeadGWDetect"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDHCP"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Domain"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegistrationEnabled"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegisterAdapterName"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpServer"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Lease"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseObtainedTime"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseTerminatesTime"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T1"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T2"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\AddressType"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\IsServerNapAware"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpConnForceBroadcastFlag"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpNetworkHint"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\IPAddress"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\SubnetMask"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\NameServer"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpIPAddress"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpSubnetMask"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpGatewayHardwareCount"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpNameServer"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpDefaultGateway"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpDomain"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpSubnetMaskOpt"
     
        Set WSkwatShell = CreateObject("WScript.Shell")
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon", "skwat"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\UseZeroBroadcast", "00000000", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDeadGWDetect", "00000001", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDHCP", "00000000", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Domain", ""
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegistrationEnabled", "00000001", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegisterAdapterName", "00000000", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpServer", "255.255.255.255", "REG_SZ"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Lease", "00015180", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseObtainedTime", "1300954047", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseTerminatesTime", "1301040447", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T1", "1300997247", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T2", "1301029647", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\AddressType", "00000000", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\IsServerNapAware", "00000000", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpConnForceBroadcastFlag", "00000000", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpNetworkHint", "C496675626F687D253163343", "REG_SZ"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\IPAddress", "192.168.20.69", "REG_EXPAND_SZ"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\SubnetMask", "255.255.255.0", "REG_EXPAND_SZ"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\NameServer", ""
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpIPAddress", "192.168.1.10"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpSubnetMask", "255.255.255.0"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpGatewayHardwareCount", "00000001", "REG_DWORD"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpNameServer", "192.168.1.1", "REG_SZ"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpDefaultGateway", "192.168.1.1", "REG_EXPAND_SZ"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpDomain", "home", "REG_SZ"
        WSkwatShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpSubnetMaskOpt", "255.255.255.0", "REG_EXPAND_SZ"
     
        ElseIf empl = "skwat" Then
        Dim WBureauShell
     
        Set DelShell = CreateObject("WScript.Shell")
        On Error Resume Next
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\UseZeroBroadcast"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDeadGWDetect"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDHCP"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Domain"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegistrationEnabled"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegisterAdapterName"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpServer"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Lease"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseObtainedTime"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseTerminatesTime"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T1"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T2"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\AddressType"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\IsServerNapAware"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpConnForceBroadcastFlag"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpNetworkHint"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\IPAddress"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\SubnetMask"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\NameServer"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpIPAddress"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpSubnetMask"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpGatewayHardwareCount"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpNameServer"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpDefaultGateway"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpDomain"
        DelShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpSubnetMaskOpt"
     
        Set WBureauShell = CreateObject("WScript.Shell")
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\ModeCon", "bureau"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\UseZeroBroadcast", "00000000", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDeadGWDetect", "00000001", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\EnableDHCP", "00000001", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Domain", ""
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegistrationEnabled", "00000001", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\RegisterAdapterName", "00000000", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\DhcpServer", "192.168.1.1", "REG_SZ"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\Lease", "86400", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseObtainedTime", "1300954494", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\LeaseTerminatesTime", "1301040894", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T1", "1300997694", "REG_DWORD"
        WBureauShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{A8B00E6C-0F5B-406C-BFA7-56F4D6BE3C2E}\T2", "1301030094", "REG_DWORD"
     
        Else
        End If
     
    End Sub
    En gros, ça fonctionne, par contre je suis obligé pour l'instant de mettre 2 fois la partie "del_reg".
    Rappel de fonctionnement :
    - Mode "Skwat" dans registre, "del_reg" puis "writebureau_reg"
    - Mode "Bureau" dans registre, "del_reg" puis "writeskwat_reg"

    C'est possible de déclarer une fois la fonction "del_reg" et l'appeler dans chaque mode sans le recopier complet comme j'ai fais ? Mon problème de base est celui-ci.

    Je poste la source.

    Merci à vous
    Fichiers attachés Fichiers attachés

  4. #4
    Membre Expert Avatar de OhMonBato
    Homme Profil pro
    Inscrit en
    Mars 2007
    Messages
    2 660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 2 660
    Par défaut
    Tu peux bien sûr mettre toute la partie "Delete"commune aux 2 cas dans une sub que tu appelles ensuite. Ca rend le code plus simple à lire et en cas de changement, ça t'évite de devoir changer 2 fois ton code.

  5. #5
    Invité
    Invité(e)
    Par défaut
    et comment tu appellerais la fonction ?

  6. #6
    Membre Expert Avatar de OhMonBato
    Homme Profil pro
    Inscrit en
    Mars 2007
    Messages
    2 660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 2 660
    Par défaut
    J'avoue ne pas comprendre ta question. Dans ton premier exemple tu mettais un "Call Del_reg" que tu as supprimé par la suite et tu demandes maintenant comment le remettre ?

Discussions similaires

  1. Réponses: 3
    Dernier message: 17/09/2008, 21h15
  2. Erreur sur appel fonction par Input/onclick
    Par heberco dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 05/09/2008, 18h46
  3. [PHP-JS] appel fonction par bouton
    Par dimi2 dans le forum Langage
    Réponses: 16
    Dernier message: 01/07/2008, 19h30
  4. [HTML & Javascript]bouton appelant fonction javascript
    Par Cirdan Telemnar dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 04/02/2008, 16h48
  5. [VB.Net] Problème appel fonction par un bouton
    Par balibo dans le forum ASP.NET
    Réponses: 4
    Dernier message: 25/11/2005, 10h48

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