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 :

Lister applications serveur


Sujet :

VBScript

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Août 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2013
    Messages : 9
    Points : 20
    Points
    20
    Par défaut Lister applications serveur
    Bonjour a tous,
    mon script me permet de lister dans un fichier txt les applications installées sur un serveur
    Problème il fonctionne en local seulement sous 2008 mais pas sur 2003 et lorsque j'essaye de lister les applicatifs directement via un fichier .txt ou les noms des serveur sont référencés ça ne fonctionne pas non plus
    ci dessous mon script.

    Merci pour votre aide
    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
    Set objFSO = WScript CreateObject("Scripting.FileSystemObject")
    Set Ts1 = fso.OpenTexteFile("nom fichier texte avec nom des serveur")
     
    'Nouveau fichier avec résultat
    Set Ts2 = objFSO.CreateTextFile("C:\Documents and Settings\mhn1\My Documents\listeapplication.txt", True)
     
    while not ts1.AtEndOfStream
    computer=ts1.ReadLine
     
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set WMIset = objWMIService.ExecQuery _
      ("Select * from Win32_Product")
    Ts2.WriteLine "Caption" & vbtab & _
      "Description" & vbtab & "Identifying Number" & vbtab & _
      "Install Date" & vbtab & "Install Location" & vbtab & _
      "Install State" & vbtab & "Name" & vbtab & _ 
      "Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
        & "Version" 
    For Each objSoftware in WMIset
      Ts2.WriteLine objSoftware.Caption & vbtab & _
      Ts2.Description & vbtab & _
      Ts2.IdentifyingNumber & vbtab & _
      Ts2.InstallDate2 & vbtab & _
      Ts2.InstallLocation & vbtab & _
      Ts2.InstallState & vbtab & _
      Ts2.Name & vbtab & _
      Ts2.PackageCache & vbtab & _
      Ts2.SKUNumber & vbtab & _
      Ts2.Vendor & vbtab & _
      Ts2.Version
    Next
    Wend
    Ts2.close
    Ts1.close

  2. #2
    Membre confirmé Avatar de pitchalov
    Homme Profil pro
    Inscrit en
    Avril 2007
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 340
    Points : 582
    Points
    582
    Par défaut
    Bonjour,
    Sans analyser le script et les requêtes WMI en détail, cette erreur saute aux yeux :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    computer=ts1.ReadLine
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    --> ta requête WMI ne se fait pas sur la liste contenue dans le fichier texte.

    Commence déjà par là :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Set objFSO = WScript CreateObject("Scripting.FileSystemObject")
    Set ts1= fso.OpenTexteFile("nom fichier texte avec nom des serveur")
    '...
    While not ts1.AtEndOfStream
    	strComputer=ts1.ReadLine
    	Set objWMIService = GetObject("winmgmts:" _
    	  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    	'...
    Wend
    '...
    Autre conseil : c'est un détail mais respecter la casse entre les variables est un plus

    Bonne continuation.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Août 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2013
    Messages : 9
    Points : 20
    Points
    20
    Par défaut
    merci beaucoup pour tes informations
    le script tourne bien
    Le seul probléme est qu'il ne me liste pas toutes les applications.
    Du coup j'utilse un autre script ,trouver sur le net qui me liste toutes les applications
    J'ai apporté une modif afin de récuperer ma liste des serveurs se trouvant dans un txt mais ca ne fonctionne pas
    En fait je ne sais pas ou placer ma variable Strcomputer dans le script
    Merci d'avance
    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
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Ts1 = fso.OpenTextFile("C:\Users\mhn1\Documents\nomsrv.txt")
    Set Ts2 = fso.CreateTextFile("C:\Users\mhn1\Documents\listeapplication.txt", True)
    while not ts1.AtEndOfStream
    Strcomputer=ts1.ReadLine 
     
    Const HKLM = &h80000002
    Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
    objCtx.Add "__ProviderArchitecture", 32
    objCtx.Add "__RequiredArchitecture", TRUE
    Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
    Set objStdRegProv = objServices.Get("StdRegProv")
     
     
     
    Ts2.WriteLine  "32-bit Applications"
     
    Ts2.WriteLine  "-------------------" 
     
    Call GetApplications 
     
    objCtx.Add "__ProviderArchitecture", 64
    objCtx.Add "__RequiredArchitecture", TRUE
    Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
    Set objStdRegProv = objServices.Get("StdRegProv") 
     
    Ts2.WriteLine "64-bit Applications" 
    Ts2.WriteLine "-------------------"
     
    On Error resume next  
     
    Call GetApplications 
     
    Sub GetApplications 
     
    ' Use ExecMethod to call the GetStringValue method
    Set Inparams = objStdRegProv.Methods_("EnumKey").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" 
     
    set Outparams = objStdRegProv.ExecMethod_("EnumKey", Inparams,,objCtx) 
     
     
    For Each strSubKey In Outparams.snames 
     
    Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & strSubKey
    Inparams.Svaluename = "DisplayName"
    set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx) 
     
    if ("" & Outparams.sValue) = "" then
     Ts2.WriteLine strSubKey
    Else
     Ts2.WriteLine Outparams.SValue
    End iF 
     
    Inparams.Svaluename = "QuietDisplayName"
    set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)
    Ts2.WriteLine "Outparams.SValue"
     
    Next 
     
    End Sub

  4. #4
    Membre confirmé Avatar de pitchalov
    Homme Profil pro
    Inscrit en
    Avril 2007
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 340
    Points : 582
    Points
    582
    Par défaut
    Bonjour,
    Un peu de lecture pour savoir où placer la variable Strcomputer : SWbemLocator.ConnectServer method
    Conseil à prendre où à laisser : Indenter ton code le rendrait beaucoup plus lisible.
    Bonne continuation

  5. #5
    Membre averti
    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
    Points : 304
    Points
    304
    Par défaut
    Bonjour help57,

    Le strComputer est pris en compte en ligne 12 et 26 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set objServices = objLocator.ConnectServer(strComputer,"root\default","","",,,,objCtx)
    Cependant, il y a également un souci avec ta boucle de lecture (ligne 4).
    Voici ce que je te propose :

    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
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Ts1 = fso.OpenTextFile("C:\Users\mhn1\Documents\nomsrv.txt")
    Set Ts2 = fso.CreateTextFile("C:\Users\mhn1\Documents\listeapplication.txt", True)
    do while not ts1.AtEndOfStream
    strComputer=ts1.ReadLine
     
    Const HKLM = &h80000002
    Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
    objCtx.Add "__ProviderArchitecture", 32
    objCtx.Add "__RequiredArchitecture", TRUE
    Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer(strComputer,"root\default","","",,,,objCtx)
    Set objStdRegProv = objServices.Get("StdRegProv")
     
    Ts2.WriteLine vbNewLine  & strComputer & vbNewLine
    Ts2.WriteLine  "32-bit Applications"
    Ts2.WriteLine  "-------------------" 
     
    Call GetApplications
     
    objCtx.Add "__ProviderArchitecture", 64
    objCtx.Add "__RequiredArchitecture", TRUE
    Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer(strComputer,"root\default","","",,,,objCtx)
    Set objStdRegProv = objServices.Get("StdRegProv") 
     
    Ts2.WriteLine "64-bit Applications" 
    Ts2.WriteLine "-------------------"
     
    On Error resume next  
     
    Call GetApplications
     
    loop
    WScript.quit
     
    Sub GetApplications
     
    ' Use ExecMethod to call the GetStringValue method
    Set Inparams = objStdRegProv.Methods_("EnumKey").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" 
     
    set Outparams = objStdRegProv.ExecMethod_("EnumKey", Inparams,,objCtx) 
     
    For Each strSubKey In Outparams.snames 
     
    Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & strSubKey
    Inparams.Svaluename = "DisplayName"
    set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx) 
     
    if ("" & Outparams.sValue) = "" then
     Ts2.WriteLine strSubKey
    Else
     Ts2.WriteLine Outparams.SValue
    End iF 
     
    Inparams.Svaluename = "QuietDisplayName"
    set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)
    Ts2.WriteLine "Outparams.SValue"
     
    Next 
    End Sub

    Edit : Pour répondre à ta question par MP ...
    Pour créer un fichier log par serveur, il suffit d'inclure la création (et le nomage) du fichier log dans ta boucle (ancienne ligne 3, nouvelle ligne 6) :

    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
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Ts1 = fso.OpenTextFile("C:\Users\mhn1\Documents\nomsrv.txt")
     
    do while not ts1.AtEndOfStream
    strComputer=ts1.ReadLine
    Set Ts2 = fso.CreateTextFile("C:\Users\mhn1\Documents\" & strComputer & ".txt", True)
     
    Const HKLM = &h80000002
    Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
    objCtx.Add "__ProviderArchitecture", 32
    objCtx.Add "__RequiredArchitecture", TRUE
    Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer(strComputer,"root\default","","",,,,objCtx)
    Set objStdRegProv = objServices.Get("StdRegProv")
     
    Ts2.WriteLine vbNewLine  & strComputer & vbNewLine
    Ts2.WriteLine  "32-bit Applications"
    Ts2.WriteLine  "-------------------" 
     
    Call GetApplications
     
    objCtx.Add "__ProviderArchitecture", 64
    objCtx.Add "__RequiredArchitecture", TRUE
    Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer(strComputer,"root\default","","",,,,objCtx)
    Set objStdRegProv = objServices.Get("StdRegProv") 
     
    Ts2.WriteLine "64-bit Applications" 
    Ts2.WriteLine "-------------------"
     
    On Error resume next  
     
    Call GetApplications
     
    loop
    WScript.quit
     
    Sub GetApplications
     
    ' Use ExecMethod to call the GetStringValue method
    Set Inparams = objStdRegProv.Methods_("EnumKey").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" 
     
    set Outparams = objStdRegProv.ExecMethod_("EnumKey", Inparams,,objCtx) 
     
    For Each strSubKey In Outparams.snames 
     
    Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & strSubKey
    Inparams.Svaluename = "DisplayName"
    set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx) 
     
    if ("" & Outparams.sValue) = "" then
     Ts2.WriteLine strSubKey
    Else
     Ts2.WriteLine Outparams.SValue
    End iF 
     
    Inparams.Svaluename = "QuietDisplayName"
    set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)
    Ts2.WriteLine "Outparams.SValue"
     
    Next 
    End Sub

  6. #6
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Août 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2013
    Messages : 9
    Points : 20
    Points
    20
    Par défaut
    Merci a tous pour votre aide.
    Le script fonctionne bien.
    Jai utilisé la solution de Cachlab

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

Discussions similaires

  1. [Réseau][Débutant]Application Serveur/Client par TCP/IP
    Par Belegkarnil dans le forum Entrée/Sortie
    Réponses: 6
    Dernier message: 13/11/2005, 13h39
  2. application serveur gérant le GUI
    Par didier.cabale dans le forum API, COM et SDKs
    Réponses: 4
    Dernier message: 03/06/2005, 11h27
  3. Réponses: 2
    Dernier message: 12/10/2004, 13h04
  4. [D8] Application serveur non disponible
    Par Keke des Iles dans le forum EDI
    Réponses: 4
    Dernier message: 27/09/2004, 12h06
  5. [VB6] Comment lister les serveurs SQL d'un domaine ?
    Par WOLO Laurent dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 29/01/2004, 08h49

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