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 :

Ajout du nom d'ordinateur au hta


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut Ajout du nom d'ordinateur au hta
    Bonjour j'ai un petit script qui permet de renommer un PC...on inscrit le nom du PC actuel et le "futur" nom du PC (dans un txtBox) que l'on veut ensuite le script s'execute...

    Toutefois j'aimerais faire en sorte que le nom soit déjà inscrit et que le "futur" nom soit suggéré aussi dans la txtBox...

    Actuellement le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Sub StartRename 
     Dim strCurrentName, strNewName
     'CheckFields for values 
     strCurrentName = window.document.getElementById("CurrentName").value 
     strNewName = window.document.getElementById("NewName").value 
     If Not ((IsEmpty(strCurrentName)) Or (IsNull(strCurrentName)) Or (IsEmpty(strNewName)) Or (IsNull(strNewName)) Or strCurrentName = "" Or strCurrentName = " " Or strNewName = "" Or strNewName = " ") Then 
        Call RenameComp (strCurrentName, strNewName) 
       Else 
        '48 + 1:  48 is ICON warning 
        Call ErrorMsg ("CurrentName or NewName field is missing") 
     End If 
    End Sub
    et html

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <tr valign="top"> 
        <td width="90" height="51" align="Left">CurrentName<br> 
        <input type="text" id="CurrentName" size="15"></td> 
        <td width="98" align="Left">NewName<br> 
            <input type="text" id="NewName" size="15"></td> 
      </tr>
    Je connais pas le window.document.getElementById("CurrentName").value

    Est ce que cette façon pourrait être logique

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    For Each objComputer In objWMI.InstancesOf("Win32_ComputerSystem") 
             strComputer =  objComputer.Name
        Next
     CurrentName.InnerText = strComputer

    Merci de m'éclairer

  2. #2
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    Avez-vous tester ceci ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    strCurrentName=CurrentName.Value
    strNewName=NewName.Value

  3. #3
    Invité
    Invité(e)
    Par défaut
    Merci

    Je viens de l'essayer mais je ne sais trop comment l'intégrer...car pour le moment je n'ai rien de positif

    L'idée est d'avoir le nom de l'ordinateur déjà inscrit comme ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    For Each objComputer In objWMI.InstancesOf("Win32_ComputerSystem") 
             strComputer =  objComputer.Name
        Next 
        td_ComputerName.InnerText = strComputer


    et le nouveau nom inscrit comme j'ai déjà sous un autre script...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    If strComputer = strComputer Then 
            Set objOption = Document.createElement("OPTION") 
            objOption.Text = strComputer & "-Archive" 
            objOption.Value = strComputer & "-Archive" 
            drp_Rename.Add(objOption)              
        End If
    Merci pour l'aide

  4. #4
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut
    Pouvez-vous poster le HTA complet ?

  5. #5
    Invité
    Invité(e)
    Par défaut
    Dans son ensemble...


    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
    <html> 
    <head> 
    <title>RenameComputer</title> 
    <script language="vbscript"> 
    Option Explicit 
    Dim iRefreshRt, iTimerID 
     
     
    Sub Window_OnLoad 
     self.Focus() 
     'Resize the HTA and move 
     window.resizeTo 320, 340 
     window.moveTo screen.width/4, screen.height/4 
    End Sub 
     
     
    'Start monitoring, call Subs/Funcs 
    Sub StartRename 
     Dim strCurrentName, strNewName
     'CheckFields for values 
     strCurrentName = window.document.getElementById("CurrentName").value
     
     
     strNewName = window.document.getElementById("NewName").value 
     If Not ((IsEmpty(strCurrentName)) Or (IsNull(strCurrentName)) Or (IsEmpty(strNewName)) Or (IsNull(strNewName)) Or strCurrentName = "" Or strCurrentName = " " Or strNewName = "" Or strNewName = " ") Then 
        Call RenameComp (strCurrentName, strNewName) 
       Else 
        '48 + 1:  48 is ICON warning 
        Call ErrorMsg ("CurrentName or NewName field is missing") 
     End If 
    End Sub 
     
     
     
    Sub RenameComp (OldComp, NewComp) 
     Dim strCmd, objShell, iSec, RadioChoice, strPingStatus, strMsg 
     iSec = iTimer (Cint(DropMenu_iTimer.Value)) 'DropMenu Value, then calc FUNC 
     RadioChoice = RadioSelect()  'Check RadioSelect 
     strPingStatus = PingReply (OldComp) 
     Select Case strPingStatus 
                 Case "ONLINE" 
                      Set objShell = CreateObject("WScript.Shell") 'using .Run to supress cmd window 
                      If RadioChoice = "ShutDown" Then 
                         strCmd = ".\SystemFiles\netdom.exe renamecomputer " & OldComp & " " & "/newname:" & NewComp & _ 
                                  " /ud:lahdsystems\helpdesk /passwordD:PasswordHere /force /reboot " & iSec 
                         objShell.Run strCmd ,0 ,1 
                        Else 
                         strCmd = ".\SystemFiles\netdom.exe renamecomputer " & OldComp & " " & "/newname:" & NewComp & _ 
                                  " /ud:lahdsystems\helpdesk /passwordD:lahd /force" 
                         objShell.Run strCmd ,0 ,1 
                      End If 
                      strMsg = "Renaming attempt, please check status:" & vbCr & vbCr & _ 
                               " CurrentCompName = " & OldComp & vbCr & _ 
                               "      NewCompName = " & NewComp 
                      MsgBox strMsg, 64, "Renaming tool" 
                 Case "OFFLINE" 
                      Call ErrorMsg ("Computer is Offline/Unreachable") 
     End Select 
    End Sub 
     
     
     
    Function PingReply (strComputer) 
     Dim wmiQuery, objWMIService, objPing, objStatus 
     Dim strCmd, objShell, objExec, strRead, i, iReply 
     If Not ((IsEmpty(strComputer)) Or (IsNull(strComputer)) Or strComputer = "" Or strComputer = " ") Then 
        iReply = 0 
        'Define WMI query to ping 
        wmiQuery = "Select * From Win32_PingStatus Where " & _ 
                   "Address = '" & strComputer & "'" 
        'Make WMI connection to local machine 
        Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") 
        Set objPing = objWMIService.ExecQuery(wmiQuery) 
        'Retrieve the status code of each ping request 
        For i = 1 To 2 
            Set objPing = objWMIService.ExecQuery(wmiQuery) 
            'Retrieve the status code of each ping request 
            For Each objStatus In objPing 
                'Return 0 for successful reply 
                If objStatus.StatusCode = 0 Then 
                   iReply = iReply + 1 
                End If 
            Next 
        Next 
     
        'Win2k and below ping check 
        If iReply <= 0 Then 
           strCmd = "ping -n 2 -w 1000 " & strComputer 
           Set objShell = CreateObject("WScript.Shell") 
           Set objExec = objShell.Exec(strCmd) 
           strRead = UCase(objExec.StdOut.ReadAll) 
           If InStr(strRead, "REPLY FROM") Then 
              iReply = iReply + 1 
           End If 
        End If 
        'Number of pings for PingStatus 
        Select Case True 
               Case (iReply <= 0) 
                    PingReply = "OFFLINE" 
               Case Else 
                    PingReply = "ONLINE" 
        End Select 
     End If 
     'Destroy VARs 
     Set objPing = Nothing 
     Set objWMIService = Nothing 
     iReply = Empty 
     strRead = Empty 
    End Function 
     
     
     
    Function RadioSelect() 
     Dim RadioVal 
     'Enum through Radio, check selected 
     Select Case True 
            Case RadioBtn(0).Checked 
                 RadioVal = "ShutDown" 
            Case RadioBtn(1).Checked 
                 RadioVal = "NoRestart" 
     End Select 
     'Assign SUB value 
     RadioSelect = RadioVal 
    End Function 
     
     
    Function ErrorMsg (msg) 
     MsgBox msg, 48, "Rename Error" 
    End Function 
     
     
    Function iTimer (TimeCheck) 
     iTimer = 60 * TimeCheck 'Calc for seconds 
    End Function 
     
     
    </script> 
    <hta:application 
       applicationname="RenameComputer"  
       border="dialog" 
       borderstyle="normal" 
       caption="RenameComputer" 
       contextmenu="no" 
       icon="images\icon.ico" 
       maximizebutton="no" 
       minimizebutton="yes" 
       navigable="no" 
       scroll="no" 
       selection="no" 
       showintaskbar="yes" 
       singleinstance="yes" 
       sysmenu="yes" 
       version="0.3" 
       windowstate="normal"    
    > 
    <style type="text/css"> 
    a:link { 
       color:#000000; 
       font-size:12px; 
       font-family:"Times New Roman", Times, serif; 
       text-decoration:none; 
       font-style: normal; 
       font-variant: normal; 
    } 
    a:visited { 
       color:#000000; 
       font-size:12px; 
       font-family:"Times New Roman", Times, serif; 
       text-decoration:none; 
       font-style: normal; 
       font-variant: normal; 
    } 
    a:hover { 
       color:#000000; 
       font-size:12px; 
       font-family:"Times New Roman", Times, serif; 
       text-decoration:underline; 
       font-style: normal; 
       font-variant: normal; 
    } 
    td { 
       font-family: "Times New Roman", Times, serif; 
       font-size: 13px; 
       font-style: normal; 
       font-weight: normal; 
       font-variant: normal; 
       color:#000000; 
       vertical-align: center; 
    } 
    .status { 
       text-align:center; 
    } 
     
    </style> 
    </head> 
     
    <body STYLE="font:9pt arial; color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=0, StartColorStr='#006d9f', EndColorStr='#ddd7ff')">  
    <table width="198" height="142" border="0" cellpadding="3"> 
      <tr> 
        <!-- <td colspan="2">Banner</td> --> 
        <td colspan="2" align="Center"><font size="4" color="#FFFFB3"><strong>RenameComputer</strong></font></td> 
      </tr> 
      <tr valign="top"> 
        <td width="90" height="51" align="Left">CurrentName<br> 
            <!-- Email address field --> 
        <input type="text" id="CurrentName" size="15"></td> 
        <td width="98" align="Left">NewName<br> 
           <!-- SMTP address field --> 
            <input type="text" id="NewName" size="15"></td> 
      </tr> 
        <tr valign="top"> 
          <td align="Center"><input name="RadioBtn" type="radio" value="RadioButton1" checked> 
              ShutDown<br> 
              <input name="RadioBtn" type="radio" value="RadioButton2"> 
              NoRestart&nbsp;</td> 
          <td align="Center" valign="middle">ShutdownTimer 
            <!-- DropDown onChange to Self.Focus() --> 
            <select size="1" name="DropMenu_iTimer" onChange="Window.Focus()"> 
              <option value="1">1 min</option> 
              <option value="2" selected>2 min</option> 
              <option value="3">3 min</option> 
              <option value="4">4 min</option> 
              <option value="5">5 min</option> 
              <option value="6">6 min</option> 
              <option value="7">7 min</option> 
              <option value="7">8 min</option> 
              <option value="9">9 min</option> 
              <option value="10">10 min</option> 
              <option value="12">12 min</option> 
              <option value="15">15 min</option> 
              <option value="20">20 min</option> 
              <option value="30">30 min</option> 
              <option value="45">45 min</option> 
              <option value="60">60 min</option> 
            </select></td> 
        </tr> 
        <tr valign="top"> 
        <td align="Center">&nbsp;</td> 
            <td align="Center" valign="middle"> 
              <!-- Submit button -->  
                <input type="button" value="Execute" onClick="StartRename"> 
            </td> 
        </tr> 
    </table> 
    </body> 
    </html>
    Merci pour l'aide

  6. #6
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    J'ai ajouté une autre fonction pour la récupération du ComputerName:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Function NomComputer()
    Set WshShell = CreateObject("WScript.Shell" )
    Set env = WshShell.Environment("PROCESS" )
    computername = env("COMPUTERNAME" )
    CurrentName.Value = computername 
    End Function
    et il faut appeler cette dernière dans la procédure Window_OnLoad
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Sub Window_OnLoad 
     self.Focus() 
     Call NomComputer()
     'Resize the HTA and move 
     window.resizeTo 320, 340 
     window.moveTo screen.width/4, screen.height/4 
    End Sub
    que le "futur" nom soit suggéré aussi dans la txtBox...
    Il suffit d'ajouter dans cette ligne :Value="NOUVEAU_NOM"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <input type="text" id="NewName" size="17" Value="NOUVEAU_NOM"></td>
    et le code devient alors :
    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
    <html> 
    <head> 
    <title>RenameComputer</title> 
    <hta:application 
       applicationname="RenameComputer"  
       border="dialog" 
       borderstyle="normal" 
       caption="RenameComputer" 
       contextmenu="no" 
       icon="Explorer.exe" 
       maximizebutton="no" 
       minimizebutton="yes" 
       navigable="no" 
       scroll="no" 
       selection="no" 
       showintaskbar="yes" 
       singleinstance="yes" 
       sysmenu="yes" 
       version="0.3" 
       windowstate="normal"    
    > 
    <style type="text/css"> 
    a:link { 
       color:#000000; 
       font-size:12px; 
       font-family:"Times New Roman", Times, serif; 
       text-decoration:none; 
       font-style: normal; 
       font-variant: normal; 
    } 
    a:visited { 
       color:#000000; 
       font-size:12px; 
       font-family:"Times New Roman", Times, serif; 
       text-decoration:none; 
       font-style: normal; 
       font-variant: normal; 
    } 
    a:hover { 
       color:#000000; 
       font-size:12px; 
       font-family:"Times New Roman", Times, serif; 
       text-decoration:underline; 
       font-style: normal; 
       font-variant: normal; 
    } 
    td { 
       font-family: "Times New Roman", Times, serif; 
       font-size: 13px; 
       font-style: normal; 
       font-weight: normal; 
       font-variant: normal; 
       color:#000000; 
       vertical-align: center; 
    } 
    .status { 
       text-align:center; 
    } 
     
    </style> 
    <script language="vbscript"> 
    'Option Explicit 
    Dim iRefreshRt, iTimerID 
     
     
    Sub Window_OnLoad 
     self.Focus() 
     Call NomComputer()
     'Resize the HTA and move 
     window.resizeTo 320, 340 
     window.moveTo screen.width/4, screen.height/4 
    End Sub 
     
     
    'Start monitoring, call Subs/Funcs 
    Sub StartRename 
     Dim strCurrentName, strNewName
     'CheckFields for values 
     strCurrentName = window.document.getElementById("CurrentName").value
     strNewName = window.document.getElementById("NewName").value 
     If Not ((IsEmpty(strCurrentName)) Or (IsNull(strCurrentName)) Or (IsEmpty(strNewName)) Or (IsNull(strNewName)) Or strCurrentName = "" Or strCurrentName = " " Or strNewName = "" Or strNewName = " ") Then 
        Call RenameComp (strCurrentName, strNewName) 
       Else 
        '48 + 1:  48 is ICON warning 
        Call ErrorMsg ("CurrentName or NewName field is missing") 
     End If 
    End Sub 
     
     
     
    Sub RenameComp (OldComp, NewComp) 
     Dim strCmd, objShell, iSec, RadioChoice, strPingStatus, strMsg 
     iSec = iTimer (Cint(DropMenu_iTimer.Value)) 'DropMenu Value, then calc FUNC 
     RadioChoice = RadioSelect()  'Check RadioSelect 
     strPingStatus = PingReply (OldComp) 
     Select Case strPingStatus 
                 Case "ONLINE" 
                      Set objShell = CreateObject("WScript.Shell") 'using .Run to supress cmd window 
                      If RadioChoice = "ShutDown" Then 
                         strCmd = ".\SystemFiles\netdom.exe renamecomputer " & OldComp & " " & "/newname:" & NewComp & _ 
                                  " /ud:lahdsystems\helpdesk /passwordD:PasswordHere /force /reboot " & iSec 
                         objShell.Run strCmd ,0 ,1 
                        Else 
                         strCmd = ".\SystemFiles\netdom.exe renamecomputer " & OldComp & " " & "/newname:" & NewComp & _ 
                                  " /ud:lahdsystems\helpdesk /passwordD:lahd /force" 
                         objShell.Run strCmd ,0 ,1 
                      End If 
                      strMsg = "Renaming attempt, please check status:" & vbCr & vbCr & _ 
                               " CurrentCompName = " & OldComp & vbCr & _ 
                               "      NewCompName = " & NewComp 
                      MsgBox strMsg, 64, "Renaming tool" 
                 Case "OFFLINE" 
                      Call ErrorMsg ("Computer is Offline/Unreachable") 
     End Select 
    End Sub 
     
     
     
    Function PingReply (strComputer) 
     Dim wmiQuery, objWMIService, objPing, objStatus 
     Dim strCmd, objShell, objExec, strRead, i, iReply 
     If Not ((IsEmpty(strComputer)) Or (IsNull(strComputer)) Or strComputer = "" Or strComputer = " ") Then 
        iReply = 0 
        'Define WMI query to ping 
        wmiQuery = "Select * From Win32_PingStatus Where " & _ 
                   "Address = '" & strComputer & "'" 
        'Make WMI connection to local machine 
        Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") 
        Set objPing = objWMIService.ExecQuery(wmiQuery) 
        'Retrieve the status code of each ping request 
        For i = 1 To 2 
            Set objPing = objWMIService.ExecQuery(wmiQuery) 
            'Retrieve the status code of each ping request 
            For Each objStatus In objPing 
                'Return 0 for successful reply 
                If objStatus.StatusCode = 0 Then 
                   iReply = iReply + 1 
                End If 
            Next 
        Next 
     
        'Win2k and below ping check 
        If iReply <= 0 Then 
           strCmd = "ping -n 2 -w 1000 " & strComputer 
           Set objShell = CreateObject("WScript.Shell") 
           Set objExec = objShell.Exec(strCmd) 
           strRead = UCase(objExec.StdOut.ReadAll) 
           If InStr(strRead, "REPLY FROM") Then 
              iReply = iReply + 1 
           End If 
        End If 
        'Number of pings for PingStatus 
        Select Case True 
               Case (iReply <= 0) 
                    PingReply = "OFFLINE" 
               Case Else 
                    PingReply = "ONLINE" 
        End Select 
     End If 
     'Destroy VARs 
     Set objPing = Nothing 
     Set objWMIService = Nothing 
     iReply = Empty 
     strRead = Empty 
    End Function 
     
     
     
    Function RadioSelect() 
     Dim RadioVal 
     'Enum through Radio, check selected 
     Select Case True 
            Case RadioBtn(0).Checked 
                 RadioVal = "ShutDown" 
            Case RadioBtn(1).Checked 
                 RadioVal = "NoRestart" 
     End Select 
     'Assign SUB value 
     RadioSelect = RadioVal 
    End Function 
     
     
    Function ErrorMsg (msg) 
     MsgBox msg, 48, "Rename Error" 
    End Function 
     
     
    Function iTimer (TimeCheck) 
     iTimer = 60 * TimeCheck 'Calc for seconds 
    End Function 
     
    Function NomComputer()
    Set WshShell = CreateObject("WScript.Shell" )
    Set env = WshShell.Environment("PROCESS" )
    computername = env("COMPUTERNAME" )
    CurrentName.Value = computername 
    End Function
     
    </script> 
    </head> 
     
    <body STYLE="font:9pt arial; color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=0, StartColorStr='#006d9f', EndColorStr='#ddd7ff')">  
    <table width="198" height="142" border="0" cellpadding="3"> 
      <tr> 
        <!-- <td colspan="2">Banner</td> --> 
        <td colspan="2" align="Center"><font size="4" color="#FFFFB3"><strong>RenameComputer</strong></font></td> 
      </tr> 
      <tr valign="top"> 
        <td width="90" height="51" align="Left">CurrentName<br> 
            <!-- Email address field --> 
        <input type="text" id="CurrentName" size="17"></td> 
        <td width="98" align="Left">NewName<br> 
           <!-- SMTP address field --> 
            <input type="text" id="NewName" size="17" Value="NOUVEAU_NOM"></td> 
      </tr> 
        <tr valign="top"> 
          <td align="Center"><input name="RadioBtn" type="radio" value="RadioButton1" checked> 
              ShutDown<br> 
              <input name="RadioBtn" type="radio" value="RadioButton2"> 
              NoRestart&nbsp;</td> 
          <td align="Center" valign="middle">ShutdownTimer 
            <!-- DropDown onChange to Self.Focus() --> 
            <select size="1" name="DropMenu_iTimer" onChange="Window.Focus()"> 
              <option value="1">1 min</option> 
              <option value="2" selected>2 min</option> 
              <option value="3">3 min</option> 
              <option value="4">4 min</option> 
              <option value="5">5 min</option> 
              <option value="6">6 min</option> 
              <option value="7">7 min</option> 
              <option value="7">8 min</option> 
              <option value="9">9 min</option> 
              <option value="10">10 min</option> 
              <option value="12">12 min</option> 
              <option value="15">15 min</option> 
              <option value="20">20 min</option> 
              <option value="30">30 min</option> 
              <option value="45">45 min</option> 
              <option value="60">60 min</option> 
            </select></td> 
        </tr> 
        <tr valign="top"> 
        <td align="Center">&nbsp;</td> 
            <td align="Center" valign="middle"> 
              <!-- Submit button -->  
                <input type="button" value="Execute" onClick="StartRename"> 
            </td> 
        </tr> 
    </table> 
    </body> 
    </html>

  7. #7
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    Voici un autre exemple complet trouvé dans le Net qui vous renseigne sur :
    • ComputerName
    • UserName
    • Domain
    • IP Adress
    • MAC Adress

    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
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    <html>
         <head>
             <title>Rename Computer</title>
             <HTA:APPLICATION
               applicationName="Rename PC"
               border="thin"
               maximizeButton="no"
               scroll="no"
               singleInstance="yes"
               showInTaskbar="yes"
               windowState="normal"
               version="1.0"
               ICON = "explorer.exe"
             >
     
             <style>
                 BODY{
                     background-color: buttonface;
                 }
                 Span.Error{
                      color: red;
                      font-size: 15px;
                      font-weight: bold;
                 }
             </style>
     
             <script language = "vbscript">
              Const ADS_SCOPE_SUBTREE = 2
              Const PC_MIN_NAME_LENGTH = 8
              Const PC_MAX_NAME_LENGTH = 11
              Dim objWMI
     
              Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
     
              Sub Window_OnLoad()
                  Call CenterWindow(350, 450)
                  Call DisplaySysInfo()
                  Call NewID_OnChange()
                  NewID.MaxLength = PC_MAX_NAME_LENGTH
                  NewID.Focus()
              End Sub
     
              Sub CenterWindow(intWidth, intHeight)
                  self.ResizeTo intWidth, intHeight
                  self.MoveTo (screen.Width - intWidth)/2, (screen.Height - intHeight)/2
              End Sub
     
              Sub DisplaySysInfo()
                  Dim clsSystemConfig
     
                  Set clsSystemConfig = New SystemConfigurations
     
                  Call GetSysInfo(clsSystemConfig)
                  Call GetIPAndMAC(clsSystemConfig)
     
                  With clsSystemConfig
                      tdComputer.InnerHTML = .ComputerName
                      tdUser.InnerHTML = .LoggedUser
                      tdDomain.InnerHTML = .Domain
                      tdIpAddress.InnerHTML = .IPAddress
                      tdMACAddress.InnerHTML = .MACAddress
                  End With
              End Sub
     
              Function GetIPAndMAC(clsSysConfig)
                  Dim colNIC
                  Dim objNIC
                  Dim strQuery, strIP
     
                  strQuery = "SELECT IPAddress, MACAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'"
                  Set colNIC = objWMI.ExecQuery(strQuery)
     
                  For Each objNIC in colNIC
                      For Each strIP in objNIC.IPAddress
                          If strIP <> "" Then
                              clsSysConfig.IPAddress = strIP
                              clsSysConfig.MACAddress = objNIC.MACAddress
                          End If
                      Next
                  Next
              End Function
     
              Function GetSysInfo(clsSysConfig)
                  Dim strQuery, strUser
     
                  strQuery = "SELECT Domain, Name, UserName FROM Win32_ComputerSystem"
                  Set colSysInfo = objWMI.ExecQuery(strQuery)
     
                  For Each objItem in colSysInfo
                      With clsSysConfig
                          .ComputerName = UCase(objItem.Name)
                          .Domain = UCase(objItem.Domain)
                          strUser = UCase(objItem.UserName)
                      End With
                  Next
     
                  clsSysConfig.LoggedUser = Right(strUser, Len(strUser) - InStrRev(strUser, "\"))
              End Function
     
              Sub Restart()
                  Dim objWSH
     
                  Set objWSH = CreateObject("WScript.Shell")
     
                  objWSH.Run "Shutdown.exe -r -t 10 -c " & chr(34) & "Restarting to finalize name change" & chr(34)
              End Sub
     
              Sub NewID_OnChange()
                  Dim strValue
                  Dim intStrLength
                  Dim isValidName : isValidName = False
     
                  NewID.Value = UCase(NewID.Value)
                  strValue = NewID.Value
                  tdNewID.InnerHTML = strValue
     
                  intStrLength = Len(strValue)
     
                  If (intStrLength < PC_MIN_NAME_LENGTH) Then
                      document.getElementByID("NewID").style.color = "red"
                      tdStatus.InnerHTML = "<font color='red'>At least " & PC_MIN_NAME_LENGTH & " characters required</font>"
                      tdADStatus.InnerHTML = "N/A"
                      tdNewID.InnerHTML = "N/A"
                      tdPingStatus.InnerHTML = "N/A"
                      btnExecute.Disabled = True
                  Else
                      document.getElementByID("NewID").style.color = "green"
                      isValidName = ValidateName(strValue)
     
                      If isValidName Then
                          btnExecute.Disabled = False
                      Else
                          btnExecute.Disabled = True
                      End If
                  End If
              End Sub
     
              Function ValidateName(strComputer)
                  Dim isInAD, isPingable
     
                  isInAD = CheckAD(strComputer)
                  isPingable = PingComputer(strComputer)
                  If isInAD Then
                      If isPingable Then
                          tdStatus.InnerHTML = "<font color='red'>Rename Not Allowed</font>"
                          tdADStatus.InnerHTML = "Found"
                          tdPingStatus.InnerHTML = "True"
                          ValidateName = False
                      Else
                          tdStatus.InnerHTML = "<font color='green'>Rename Allowed</font>"
                          tdADStatus.InnerHTML = "Found"
                          tdPingStatus.InnerHTML = "False"
                          ValidateName = True
                      End If
                  Else
                      tdStatus.InnerHTML = "<font color='green'>Rename Allowed</font>"
                      tdADStatus.InnerHTML = "Not Found"
                      tdPingStatus.InnerHTML = "False"
                      ValidateName = True
                  End If
              End Function
     
              Function CheckAD(strComputer)
                  Dim objConnection, objCommand, objRecordSet
     
                  Set objConnection = CreateObject("ADODB.Connection")
                  Set objCommand =   CreateObject("ADODB.Command")
                  objConnection.Provider = "ADsDSOObject"
                  objConnection.Open "Active Directory Provider"
     
                  Set objCommand.ActiveConnection = objConnection
                  objCommand.CommandText = "Select Name from 'LDAP://DC=MYDOMAIN,DC=COM' " _
                                         & "Where objectClass='computer' AND Name='" & strComputer & "'"  
                  objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
     
                  Set objRecordSet = objCommand.Execute
     
                  On Error Resume Next
                  objRecordSet.MoveFirst
     
                  If objRecordSet.EoF Then
                      CheckAD = False
                  Else
                      CheckAD = True
                  End If
     
                  Err.Clear
              End Function
     
              Function PingComputer(strComputer)
                  Dim objPingStatus
     
                  Set colPings = objWMI.ExecQuery("SELECT StatusCode FROM Win32_PingStatus WHERE Address='" & strComputer & "'")
     
                  For Each objPingStatus In colPings
                      If objPingStatus.StatusCode = 0 Then
                          PingComputer = True
                      Else
                          PingComputer = False
                      End If
                  Next
              End Function
     
              Sub RenameDrive(strDrive, strVolumeLabel)
                  Dim strQuery
                  Dim objDrive
                  Dim colDrives
     
                  strQuery = "SELECT * FROM Win32_LogicalDisk where DeviceID = '"& strDrive & "'"
                  Set colDrives = objWMI.ExecQuery(strQuery)
     
                  For Each objDrive In colDrives
                          objDrive.VolumeName = strVolumeLabel
                          objDrive.Put_
                  Next
              End Sub
     
              Sub ChangeSysVars(strValue)
                  Dim objWSH, objSysEnv
     
                  Set objWSH = CreateObject("WScript.Shell")
     
                  Set objSysEnv = objWSH.Environment("SYSTEM")
                  objSysEnv("MACHNO") = strValue
     
                  objWSH.RegWrite "HKCR\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\LocalizedString", strValue, "REG_SZ"
              End Sub
     
              Sub RenameComputer(strComputer)
                  Dim strQuery
                  Dim colComputers
                  Dim objComputer
     
                  strQuery = "SELECT * FROM Win32_ComputerSystem"
                  Set colComputers = objWMI.ExecQuery(strQuery)
     
                  For Each objComputer In colComputers
                      objComputer.Rename(strComputer)
                  Next
              End Sub
     
              Sub btnExecute_OnClick()
                  Dim strNewID
     
                  strNewID = NewID.Value
     
                  Call RenameDrive("C:", strNewID)
                  Call ChangeSysVars(strNewID)
                  Call RenameComputer(strNewID)
     
                  If Err.Number <> 0 Then
                      Msgbox "Failed to properly rename this computer." & vbCrLf & "Error Number: " & Err.Number, vbApplicationModal & vbCritical, "Rename Error"
                      Window.Close()
                  Else
                      Restart
                      Window.Close()
                  End If
              End Sub
     
              Class SystemConfigurations
                  Public ComputerName
                  Public LoggedUser
                  Public Domain
                  Public IPAddress
                  Public MACAddress
              End Class
             </script>
         </head>
     
         <body>
         </body>
              <fieldset>
                  <legend>System Information</legend>
                  <table width=100%>
                      <tr>
                          <td><b>Current Name:</b></td>
                          <td id="tdComputer"></td>
                      </tr>
                      <tr>
                          <td><b>User:</b></td>
                          <td id="tdUser"></td>
                      </tr>
                      <tr>
                          <td><b>Domain:</b></td>
                          <td id="tdDomain"></td>
                      </tr>
                      <tr>
                          <td><b>IP Address:</b></td>
                          <td id="tdIPAddress"></td>
                      </tr>
                      <tr>
                           <td><b>MAC Address:</b></td>
                          <td id="tdMACAddress"></td>
                      </tr>
                  </table>
              </fieldset>
              <br />
              <fieldset>
                  <legend>Rename Status</legend>
                  <table width=100%>    
                      <tr valign="top">
                          <td><b>Status:</b></td>
                          <td id="tdStatus"></td>
                      </tr>
                      <tr valign="top">
                          <td><b>New ID:</b></td>
                          <td id="tdNewID"></td>
                      </tr>                 
                      <tr valign="top">
                          <td><b>AD Status:</b></td>
                          <td id="tdADStatus"></b></td>
                      </tr>
                      <tr valign="top">
                          <td><b>Pingable:</b></td>
                          <td id="tdPingStatus"></b></td>
                      </tr>
                  </table>
              </fieldset>
              <br />
              <center>
                  <table>
                      <tr>
                          <td><b>New Name:</b></td>
                          <td><input type='text' id="NewID"></td>
                      </tr>
                  </table>
                  <br>
                  <button id="btnExecute">Rename Computer</button>
              </center>
     </html>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Modification d'un nom d'ordinateur
    Par lessoy dans le forum Windows Serveur
    Réponses: 9
    Dernier message: 13/07/2007, 16h27
  2. pb de nom d'ordinateur
    Par loveflower dans le forum Windows XP
    Réponses: 5
    Dernier message: 26/12/2006, 20h59
  3. ajouter un nom à une liste déroulante
    Par lolo_bob2 dans le forum IHM
    Réponses: 8
    Dernier message: 25/10/2006, 20h21
  4. GetLocaleInfo () et nom d'ordinateur
    Par robv dans le forum C++
    Réponses: 4
    Dernier message: 18/10/2006, 18h30
  5. Comment obtenir la liste des noms des ordinateurs du réseau ?
    Par da_latifa dans le forum Web & réseau
    Réponses: 2
    Dernier message: 17/08/2005, 11h58

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