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 :

Script Affichage adresse Ip + nom de machine


Sujet :

VBScript

  1. #1
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Avril 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2014
    Messages : 3
    Points : 2
    Points
    2
    Par défaut Script Affichage adresse Ip + nom de machine
    Bonjour,

    voila après plusieurs heures de réflexion et de recherche je tourne réellement en ronds alors svp même si c'est bateau Aidé moi!!!!
    ps: j'ai commencer le script il y à quelques jours ...

    voila j'aimerais diffuser un fichier sur plusieurs machine pour que quand on l'ouvre il nous affiche divers informations de la machine
    je pense être sur la bonne voie,

    j'arrive à afficher l'adresse ip de la machine en utilisant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     Set colAdapters = objWMIService.ExecQuery _
        ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    j'arrive à afficher le nom de machine à partir d'un autre script en utilisant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
    Mais comment utiliser les deux dans un seul et même script?????????


    voilà mes deux scripte :

    Scripte pour afficher l'adresse ip :

    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
    Dim objWMIService
    Dim strComputer
     
    strComputer = "."
     
    Set objWMIService = GetObject("winmgmts:\\" _
    & strComputer & "\root\cimv2") 
     
    Set colAdapters = objWMIService.ExecQuery _
        ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
     
    Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
     
    For Each objAdapter in colAdapters
     
    msgbox "Adresse IP: " & objAdapter.IPAddress(i)
     
    Next


    Scripte Affiche le nom de machine :

    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
    Dim objWMIService
    Dim strComputer
     
    strComputer = "."
     
    Set objWMIService = GetObject("winmgmts:\\" _
    & strComputer & "\root\cimv2")
     
    Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
     
    For Each objItem in colItems
     
    msgbox "Nom de l'Ordinateur: " & objItem.CSName
    Next
    Merci d'avance!

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut Deux en Un (2 en 1)

    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
    Option Explicit
    Dim strComputer,colAdapters,objAdapter,objWMIService
    Dim objItem,colItems,MyIP,ComputerName,i
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" _
    & strComputer & "\root\cimv2")
     
    Set colAdapters = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
     
    Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
     
    For Each objAdapter in colAdapters
        MyIp = MyIp & objAdapter.IPAddress(i) & VbcrLf & VbTab
    Next
     
    For Each objItem in colItems
        ComputerName = ComputerName & objItem.CSName
    Next
     
    Msgbox "Nom de l'ordinateur : " & ComputerName & VbcrLf & VbcrLf &_
    "Adresse IP : " & MyIp ,64,"Nom du Computer + Adresses IP(s)"

  3. #3
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Avril 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2014
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    Merci!!!!! trop fort!

    par contre à quoi sert à la fin (j'ai essayer sans sa fonctionne aussi???) : ,64,"Nom du Computer + Adresses IP(s)"

  4. #4
    Modérateur
    Avatar de l_autodidacte
    Homme Profil pro
    Retraité : Directeur de lycée/Professeur de sciences physiques
    Inscrit en
    Juillet 2009
    Messages
    2 415
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Retraité : Directeur de lycée/Professeur de sciences physiques
    Secteur : Enseignement

    Informations forums :
    Inscription : Juillet 2009
    Messages : 2 415
    Points : 5 806
    Points
    5 806
    Par défaut
    Quand on utilise la fonction MsgBox, on lui fournit des arguments MsgBox "Ici on met le message à afficher",Type icône accompagnant le message, "Texte à afficher dans la barre de titres de la boîte de message"Le nombre 64 peut être remplacé par vbInformation qui affiche une petite icône ou c'est écrit la lettre i.
    Dans l'aide Script56.chm, tape le mot MsgBox et tu trouveras la signification de chaque terme.

    [EDIT] : oublié de mentionner que le second argument comporte aussi le type de bouton à afficher
    sur la boîte de message
    Ne pas oublier le tag si satisfait.
    Voter pour toute réponse satisfaisante avec pour encourager les intervenants.
    Balises CODE indispensables. Regardez ICI
    Toujours utiliser la clause Option Explicit(VBx, VBS ou VBA) et Ne jamais typer variables et/ou fonctions en VBS.
    Vous pouvez consulter mes contributions
    Ne pas oublier de consulter les différentes FAQs et les Cours/Tutoriels VB6/VBScript
    Ne pas oublier L'Aide VBScript et MSDN VB6 Fr

  5. #5
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Avril 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2014
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    c'est noté merci pour l'info

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut Un petit bonus en HTA : PC Information + Process Killer

    Voici un petit bonus en HTA : PC Information + Process Killer.hta
    Copier et coller ce code et enregistrer le sous PCInfo.hta
    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
    <Html>
    <Head>
    <Title>PC Information + Process Killer © Hackoo Crackoo © 2013</Title>
    <HTA:Application
    Caption = Yes
    Icon = "Explorer.exe"
    Border = Thick
    ShowInTaskBar = Yes
    SingleInstance = Yes
    MaximizeButton = Yes
    MinimizeButton = Yes>
    <META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
    <script Language = VBScript>
    Option Explicit
    Dim fso,Titre,LogFile
    Titre = "PC Information + Process Killer © Hackoo Crackoo © 2013"
    Set fso = CreateObject("Scripting.FileSystemObject")
    LogFile = "ProcessKilled.txt"
    If fso.FileExists(LogFile) Then fso.DeleteFile LogFile
    '**********************************************************************************************
    Sub Window_OnLoad
        Dim intWidth,intHeight,strIPInfo,arrIPInfo
        intWidth = 800
        intHeight = 600
        Me.ResizeTo intWidth, intHeight
        Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
        span_computername.innerHTML = GetComputerName()
        span_username.innerHTML = GetUserName()
        strIPInfo = GetIPInformation()
        If InStr(strIPInfo, ";") > 0 Then
            arrIPInfo = Split(strIPInfo, ";")
            If UBound(arrIPInfo) >= 3 Then
                span_ipaddress.InnerHTML = arrIPInfo(0)
                span_subnetmask.InnerHTML = arrIPInfo(1)
                span_defaultgateway.InnerHTML = arrIPInfo(2)
                span_primarydns.InnerHTML = arrIPInfo(3)
                If UBound(arrIPInfo) = 4 Then
                    span_secondarydns.InnerHTML = arrIPInfo(4)
                End If
            End If
        End If
        GenererCheckBox()
    End Sub
    '**********************************************************************************************
    Function GetComputerName()
        Dim objNetwork
        Set objNetwork = CreateObject("WScript.Network")
        GetComputerName = objNetwork.ComputerName
    End Function
    '**********************************************************************************************
    Function GetUserName()
        Dim objNetwork
        Set objNetwork = CreateObject("WScript.Network")
        GetUserName = objNetwork.UserName
    End Function
    '**********************************************************************************************
    Function GetIPInformation()
        Dim strComputer,objWMIService,colNetAdapters,strDetails,objAdapter
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colNetAdapters = objWMIService.ExecQuery _
        ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True")
        strDetails = ""
        For Each objAdapter In colNetAdapters
            If IsNull(objAdapter.IPAddress) = False And IsNull(objAdapter.DefaultIPGateway) = False Then
                If Join(objAdapter.IPAddress) <> "0.0.0.0" Then
                    If strDetails = "" Then
                        strDetails = Join(objAdapter.IPAddress) & ";"
                        strDetails = strDetails & Join(objAdapter.IPSubnet) & ";"
                        strDetails = strDetails & Join(objAdapter.DefaultIPGateway) & ";"
                        strDetails = strDetails & Join(objAdapter.DNSServerSearchOrder, ";")
                    End If
                End If
            End If
        Next
        GetIPInformation = strDetails
    End Function
    '**********************************************************************************************
    Sub SelectAll()
        Dim checkbox
        For Each checkbox In CheckboxOption
            checkbox.Checked = True 
        Next
    End Sub
    '**********************************************************************************************
    Sub UnSelectAll()
        Dim checkbox 
        For Each checkbox In CheckboxOption
            checkbox.Checked = False 
        Next
    End Sub
    '**********************************************************************************************
    Sub KillThis()
        Dim LogFile,ws,fso,checkbox
        LogFile = "ProcessKilled.txt"
        Set Ws  = CreateObject("Wscript.Shell")
        Set FSO = CreateObject("Scripting.FileSystemObject")
        For Each checkbox In CheckboxOption
            If checkbox.Checked = True Then 
                Kill(checkbox.Value)
            End If
        Next
        If FSO.FileExists(LogFile) Then
            MsgBox Formater(LogFile),64,Titre
            ws.run LogFile,1,True
        End If
    End Sub
    '**********************************************************************************************
    Sub Kill(Process)
        Dim FSO,Ws,MyDate,Command,Execution,LogFile
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set Ws  = CreateObject("Wscript.Shell")
        LogFile = "ProcessKilled.txt"
        MyDate = "cmd /c echo %date% ^@ %time%  >> "&LogFile&""
        Command = "cmd /c Taskkill /F /IM "&Process&" >> "&LogFile&""
        Execution = Ws.Run(MyDate,0,True)
        Execution = Ws.Run(Command,0,True)
    End Sub
    '**********************************************************************************************
    'Fonction pour formater et remplacer les caractères spéciaux unicode dans le LogFile
    Function Formater(LogFile)
        Dim fso,fRead,fWrite,Text
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set fRead = fso.OpenTextFile(LogFile,1)
        Text = fRead.ReadAll
        fRead.Close
        Set fWrite = fso.OpenTextFile(LogFile,2,True)
        Text = Replace(Text,"‚","é")
        Text = Replace(Text,"ے"," ")
        Text = Replace(Text,"ˆ","ê")
        Text = Replace(Text,"‡","ç")
        Text = Replace(Text,"“","ô")
        Text = Replace(Text,"…","à")
        Text = Replace(Text,"ٹ","è")
        Text = Replace(Text,"ƒ","â")
        Text = Replace(Text,"?"," ")
        fWrite.WriteLine Text
        Formater = Text
    End Function
    '**********************************************************************************************
    'Fonction pour ajouter les doubles quotes dans une variable
    Function DblQuote(strIn)
        DblQuote = Chr(34) & strIn & Chr(34)
    End Function
    '**********************************************************************************************
    Sub GenererCheckBox()
        Const ForReading = 1
        Dim StrHTML,objFSO,strNewFile,ListProcess,objFile,LireTout,MyTab,i
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        StrHTML = "<h2><b><font color='red'>Processus à Arrêter</font></b></h2>"
        strNewFile = "Process2Kill.txt"
        If Not objFSO.FileExists(strNewFile) Then
                ListProcess = "iexplore.exe" & vbCrLf & "FireFox.exe" & vbCrLf & "Chrome.exe" & vbCrLf &_
                "outlook.exe" & vbCrLf & "winword.exe" & vbCrLf & "excel.exe" & vbCrLf & "searchindexer.exe" & vbCrLF & "searchprotocolhost.exe"
                Call WriteProcessFile(ListProcess,strNewFile)
        End If
        Set objFile = objFSO.OpenTextFile(strNewFile,ForReading)
        LireTout = objFile.ReadAll
        MyTab = Split(LireTout,vbCrLf)
        For i = LBound(MyTab) To UBound(MyTab)
            StrHTML = StrHTML & MySpanCheckBox.InnerHTML &_
            "<br><input type='checkbox' name='CheckboxOption' value=" & MyTab(i) & " title = " & MyTab(i) & " Checked = 'True'>" & MyTab(i)
        Next
        MySpanCheckBox.InnerHTML = StrHTML
    End Sub
    '**********************************************************************************************
    'Fonction pour écrire les processus par défaut dans un fichier texte
    Sub WriteProcessFile(strText,File)
        Dim fs,ts 
        Const ForWriting = 2
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ts = fs.OpenTextFile(File,ForWriting,True)
        ts.Write strText
        ts.Close
    End Sub
    '**********************************************************************************************
    </script>
    <body text="white" style="background-color:DarkOrange">
    <table width= "90%" border="0" align="center">
    <tr>
    <td align="center" colspan="2">
    <h2>PC INFORMATION</h2><br>
    </td>
    </tr>
    <tr>
    <td>
    Le Nom de l'ordinateur est : 
    </td>
    <td>
    <span id="span_computername"></span>
    </td>
    </tr>
    <tr>
    <td>
    Vous êtes connecté en tant que :
    </td>
    <td>
    <span id="span_username"></span>
    </td>
    </tr>
    <tr>
    <td>
    Adresse IP est : 
    </td>
    <td>
    <span id="span_ipaddress"></span>
    </td>
    </tr>
    <tr>
    <td>
    Le masque de sous-réseau est :
    </td>
    <td>
    <span id="span_subnetmask"></span>
    </td>
    </tr>
    <tr>
    <td>
    Passarelle par défaut est :
    </td>
    <td>
    <span id="span_defaultgateway"></span>
    </td>
    </tr>
    <tr>
    <td>
    Serveur DNS Primaire  est :
    </td>
    <td>
    <span id="span_primarydns"></span>
    </td>
    </tr>
    <tr>
    <td>
    Serveur DNS Secondaire  est :
    </td>
    <td>
    <span id="span_secondarydns"></span>
    </td>
    </tr>
    </table>
    </body>
    <center><input type="button" name="SelectAll" id="SelectAll" value="Tout sélectionner" onclick="SelectAll">
    <input type="button" name="UnSelectAll" id="UnSelectAll" value="Tout désélectionner" onclick="UnSelectAll">
    <input type="button" name="KillThis" id="KillThis" value="Arrêter le(s) Processus" onclick="KillThis()">
    <table>
    <tr>
    <td>
    <span id="MySpanCheckBox"></span>
    </td>
    </tr>
    </table>
    </html>

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

Discussions similaires

  1. affichage noms des machines actif sur un reseau
    Par jalalnet dans le forum VB.NET
    Réponses: 3
    Dernier message: 04/04/2011, 10h04
  2. [À télécharger] Résoudre une adresse IP en nom de machine
    Par SfJ5Rpw8 dans le forum Vos téléchargements VB6
    Réponses: 0
    Dernier message: 14/11/2010, 17h00
  3. [À télécharger] Résoudre un nom de machine en adresse IP
    Par SfJ5Rpw8 dans le forum Vos téléchargements VB6
    Réponses: 0
    Dernier message: 14/11/2010, 16h55
  4. [SCRIPT WMI]Obtenir l'adresse MAC d'une machine
    Par zell45 dans le forum Windows
    Réponses: 7
    Dernier message: 05/04/2006, 08h32

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