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 :

Droits d'admin et gestion d'erreurs


Sujet :

VBScript

  1. #1
    Membre expérimenté
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Par défaut Droits d'admin et gestion d'erreurs
    Bonjour à tous !

    J'aurais besoin d'un petit coup de main concernant la gestion d'erreurs ...
    Voici mon code (fichier .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
    <title>Informations sur un ordinateur distant</title>
    <HTA:APPLICATION
    APPLICATIONNAME="Login Details"
    BORDER="thin"
    SCROLL="no"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="normal"></head>
     
    <script language="VBScript">
     
    Public strComputer
    Dim WSHShell
     
    On error resume next
     
    Sub Window_onLoad
    Me.ResizeTo 400,300
    Me.MoveTo ((Screen.Width / 2) - 200),((Screen.Height / 2) - 150)
    End Sub
     
    Sub Default_Buttons
    If Window.Event.KeyCode = 13 Then
    btn_logindetails.Click
    End If
    End Sub
     
    Sub Get_Login_Details
    strComputer = txt_computer.value
    if strComputer = "" Then
    msgbox "Nom de machine ou adresse IP invalide",vbOKOnly,"Réessayez !"
    Exit Sub
    End If
     
    If Ping(strComputer) = False Then
    msgbox "L'ordinateur " & strComputer & " ne répond pas.",vbOkOnly, "Ordinateur introuvable."
    Exit Sub
    End If
     
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    if Err.Number <> 0 Then MsgBox "Vérifier que vous disposez des droits d'admin", VbOKOnly,"Erreur droits insuffisants" : Exit Sub
     
    Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
     
    Set colComputerIP = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration")
     
    Set colSystemInfo = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem",,48)
     
    For Each objComputer in colComputer
    UsrNom = "Aucun"
    If Not IsNull(objComputer.UserName) Then UsrNom = objComputer.UserName
    strUserName = "Utilisateur : " & UsrNom
    strHostName = "Nom machine : " & objComputer.Name
    Next
     
    For Each IPConfig in colComputerIP
    If Not IsNull(IPConfig.IPAddress) Then
    For intIPCount = LBound(IPConfig.IPAddress) _
    to UBound(IPConfig.IPAddress)
    strIPAddress = strIPAddress & "Adresse IP : " & IPConfig.IPAddress(intIPCount) & "~"
    next
    end if
    Next
     
    If Right(strIPAddress, 1) = "~" Then
    strIPAddress = Left(strIPAddress, Len(strIPAddress) - 1)
    End If
    strIPAddress = Replace(strIPAddress, "~", vbCrLf)
     
    For Each objItem in colSystemInfo
    strOS_Caption = "Système : " & objItem.Caption
    strOS_SPVersion = "Version SP : " & objItem.CSDVersion
    strOS_VerNumber = "N° Version : " & objItem.Version
    Next
     
    Set WSHShell = CreateObject("WScript.Shell")
    reboot = Msgbox(strUserName & vbcrlf & strHostName & vbcrlf & strIPAddress & vbcrlf & strOS_Caption & vbcrlf & strOS_SPVersion & vbcrlf & strOS_VerNumber& vbcrlf& VbCrLf & VbCrLf & "Voulez-vous redémarrer le poste ?", vbYesNo, "Informations")
    if reboot = 6 then
    WSHShell.Run ("C:\WINDOWS\system32\shutdown.exe -m \\" & strComputer & " -r -f -t 0")
    Set oSh = CreateObject("WScript.Shell")
    Set oExec = oSh.Exec ("WScript popup.vbs " & strComputer)
    Do While Ping(strComputer) = True
    Loop
    Do While Ping(strComputer) = False
    Loop
    oExec.Terminate
    MsgBox "Le poste " & strComputer & " a redémarré.", VbOKOnly,"Poste redémarré"
    Exit Sub
    End if
    End Sub
     
    Function Ping(strComputer)
    Dim objShell, boolCode
    Set objShell = CreateObject("WScript.Shell")
    boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
    If boolCode = 0 Then
    Ping = True
    Else
    Ping = False
    End If
    End Function
    </script>
     
    <body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
    <table width='80%' height = '100%' align='center' border='0'><tr height='20%'><td></td></tr>
    <tr height='10%'><td align='center'>Nom machine ou adresse IP:</td></tr
    <tr height='20%'><td align='center'>
    <input type="text" value="" name="txt_computer" maxlength='15' size='16'>
    </td></tr><tr height='30%'><td align='center'>
    <input type="button" value="Lancer le test" name="btn_logindetails"  onClick="Get_Login_Details">
    </td></tr><tr height='20%'><td></td></tr></table></body>
    Si j'utilise cet outil avec un compte admin, aucun souci.
    Si j'utilise un compte ayant des droits insuffisants, j'obtiens :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Une erreur est survenue dans le script de cette page.
    Ligne: 39
    Caractères: 1
    Erreur: Permission refusée: 'GetObject'
    Code: 0
    ...
    Je voudrais obtenir une popup "Vérifier que vous disposez des droits d'admin" (ligne 40).
    Quelqu'un pourrait-il me conseiller ?

  2. #2
    Membre expérimenté
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Par défaut
    Ah, je rajoute le fichier "popup.vbs", appelé par le script précédent, si vous voulez tester l'appli ...

    popup.vbs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Set oSh = CreateObject("WScript.Shell")
    NomPC = wscript.arguments(0)
    Osh.PopUp("Le poste " & NomPC & " s'éteint."  & VbCrLf & VbCrLf & "Un message vous avertira lorsqu'il aura redémarré."  & VbCrLf & VbCrLf & "Merci de patienter ..."), 10000

  3. #3
    Membre expérimenté
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Par défaut
    Bon bin j'ai trouvé ... Quoi que je ne vois pas trop pourquoi ça ne fonctionnait pas avant ...

    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
    <title>Informations sur un ordinateur distant</title>
    <HTA:APPLICATION
    APPLICATIONNAME="Login Details"
    BORDER="thin"
    SCROLL="no"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="normal"></head>
     
    <script language="VBScript">
     
    Public strComputer
    Dim WSHShell
     
    Sub Window_onLoad
    Me.ResizeTo 400,300
    Me.MoveTo ((Screen.Width / 2) - 200),((Screen.Height / 2) - 150)
    End Sub
     
    Sub Default_Buttons
    If Window.Event.KeyCode = 13 Then
    btn_logindetails.Click
    End If
    End Sub
     
    Sub Get_Login_Details
    strComputer = txt_computer.value
    if strComputer = "" Then
    msgbox "Nom de machine ou adresse IP invalide",vbOKOnly,"Réessayez !"
    Exit Sub
    End If
     
    If Ping(strComputer) = False Then
    msgbox "L'ordinateur " & strComputer & " ne répond pas.",vbOkOnly, "Ordinateur introuvable."
    Exit Sub
    End If
     
    On error resume next
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    if err.number <> 0 then MsgBox "Vérifier que vous disposez des droits d'admin", VbOKOnly,"Erreur droits insuffisants" : Exit Sub
    On error goto 0
     
    Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
    Set colComputerIP = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration")
    Set colSystemInfo = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem",,48)
     
    For Each objComputer in colComputer
    UsrNom = "Aucun"
    If Not IsNull(objComputer.UserName) Then UsrNom = objComputer.UserName
    strUserName = "Utilisateur : " & UsrNom
    strHostName = "Nom machine : " & objComputer.Name
    Next
     
    For Each IPConfig in colComputerIP
    If Not IsNull(IPConfig.IPAddress) Then
    For intIPCount = LBound(IPConfig.IPAddress) _
    to UBound(IPConfig.IPAddress)
    strIPAddress = strIPAddress & "Adresse IP : " & IPConfig.IPAddress(intIPCount) & "~"
    next
    end if
    Next
     
    If Right(strIPAddress, 1) = "~" Then
    strIPAddress = Left(strIPAddress, Len(strIPAddress) - 1)
    End If
    strIPAddress = Replace(strIPAddress, "~", vbCrLf)
     
    For Each objItem in colSystemInfo
    strOS_Caption = "Système : " & objItem.Caption
    strOS_SPVersion = "Version SP : " & objItem.CSDVersion
    strOS_VerNumber = "N° Version : " & objItem.Version
    Next
     
    Set WSHShell = CreateObject("WScript.Shell")
    reboot = Msgbox(strUserName & vbcrlf & strHostName & vbcrlf & strIPAddress & vbcrlf & strOS_Caption & vbcrlf & strOS_SPVersion & vbcrlf & strOS_VerNumber & VbCrLf & VbCrLf & "Voulez-vous redémarrer le poste ?", vbYesNo, "Informations")
    if reboot = 6 then
    WSHShell.Run ("C:\WINDOWS\system32\shutdown.exe -m \\" & strComputer & " -r -f -t 0")
    Set oSh = CreateObject("WScript.Shell")
    Set oExec = oSh.Exec ("WScript popup.vbs " & strComputer)
    Do While Ping(strComputer) = True
    Loop
    Do While Ping(strComputer) = False
    Loop
    oExec.Terminate
    MsgBox "Le poste " & strComputer & " a redémarré.", VbOKOnly,"Poste redémarré"
    Exit Sub
    End if
    End Sub
     
    Function Ping(strComputer)
    Dim objShell, boolCode
    Set objShell = CreateObject("WScript.Shell")
    boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
    If boolCode = 0 Then
    Ping = True
    Else
    Ping = False
    End If
    End Function
    </script>
     
    <body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
    <table width='80%' height = '100%' align='center' border='0'><tr height='20%'><td></td></tr>
    <tr height='10%'><td align='center'>Nom machine ou adresse IP:</td></tr
    <tr height='20%'><td align='center'>
    <input type="text" value="" name="txt_computer" maxlength='15' size='16'>
    </td></tr><tr height='30%'><td align='center'>
    <input type="button" value="Lancer le test" name="btn_logindetails"  onClick="Get_Login_Details">
    </td></tr><tr height='20%'><td></td></tr></table></body>
    [...]

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

Discussions similaires

  1. gestion d'erreur et de transactions....
    Par Dge dans le forum MS SQL Server
    Réponses: 9
    Dernier message: 08/02/2006, 22h20
  2. [Struts-Validator] Gestion d'erreurs
    Par sylvain_neus dans le forum Struts 1
    Réponses: 14
    Dernier message: 09/04/2004, 15h15
  3. [XSLT]Est ce qu'il y'a la gestion des erreur en xslt ?
    Par miloud dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 04/02/2004, 17h19
  4. [LG]tests pour la gestion d'erreur
    Par le 27 dans le forum Langage
    Réponses: 3
    Dernier message: 22/12/2003, 20h44
  5. [LG]gestion des erreurs
    Par frontin dans le forum Langage
    Réponses: 3
    Dernier message: 29/11/2003, 22h41

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