Problème VbScript / GetOwner

Résolu
boudzz Messages postés 9 Date d'inscription samedi 14 mai 2005 Statut Membre Dernière intervention 18 juin 2010 - 15 juin 2005 à 10:23
boudzz Messages postés 9 Date d'inscription samedi 14 mai 2005 Statut Membre Dernière intervention 18 juin 2010 - 15 juin 2005 à 10:38
Bonjour, je cherche à récupérer le propriétaire d'un process pour
effectuer un traîtement : je lance l'install d'un fichier *.msi ->
process : msiexec.exe et je regarde si l'utilisateur est système ou
autre (puis je fais un traitement pour vérifier que mon msi est
installé). L'erreur est : Objet requis GetOwner(....)

Voici mon code :



'Définition de mes constantes pour le post-traîtement (base de registre).

Const HKLM = &H80000002

chemin = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

'definition de requête wmi

sComputer = "." ' use "." for local computer

Set oWmi = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\" _

& sComputer & "\root\cimv2")



'definition des objets vbscripts

Set Fso = CreateObject("Scripting.FileSystemObject")

Set WshShell = CreateObject("WScript.Shell")

Set oReg = GetObject("winmgmts:root\default:StdRegProv")

Set WshNetwork = CreateObject("WScript.Network")



UserName =WshNetwork.UserName



Dim SubKey, arrSubKeys, Display

Dim ma_comparaison, php, objProcess, colProcessList, NomUser, NomDomain

Dim Key(), affiche(), version(), I, toto



'Il faut exécuter le package php ; Le problème vient du fait qu on ne connait pas la lettre du lecteur de

'cd pour notre chemin -> recherche de fichier "at-collab" : for each fso.drive...

WshShell.Run(CHR(34) & "C:/Installs/php5/msi-php/PHP5.msi" & CHR(34))



'------------------------------ tempo fenetre php ------------------------------

'tempo fenetre php

wscript.sleep(3000)

do

Set colProcessList = oWmi.ExecQuery _

("Select * from Win32_Process Where Name = 'msiexec.exe'")

For Each objProcess in colProcessList

Set toto = objProcess.GetOwner(NomUser)

If NomUser = UserName Then wscript.sleep(500)

Next

loop while (colProcessList.count >= 2)



wscript.sleep(1000)

'-------------------------------------------------------------------------------



'Vérifions que notre utilisateur a installé php



'Enumération des clés (logiciels installés sur l ordi) dans "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

oReg.EnumKey HKLM, chemin, arrSubKeys

'initialisation de I

I = 0



For Each SubKey In arrSubKeys

ReDim Preserve Key(I)

ReDim Preserve affiche(I)

Key(I) = SubKey

oReg.GetStringValue HKLM, chemin & "" & SubKey, "DisplayName", Display

affiche(I) = Display

' Test de présence de php

php = LCase(left(affiche(I),3))

ma_comparaison = StrComp(php, "php", 1)

if (ma_comparaison = 0) then

GinstallePHP = 1

phpinstalle = 1

MsgBox " PHP a été installé avec succès :)", vbOKOnly + vbDefaultButton1 + vbInformation, ""

WshShell.Run(CHR(34) & "C:/php5conf.vbs" & CHR(34))

End If

I = I + 1

Next



If GinstallePHP = 0 Then

Reponse = MsgBox(" Vous n'avez pas installez PHP !
Etes-vous sûr de vouloir continuer ?", vbYesNo + vbDefaultButton1 +
vbCritical, "Attention !")

If (Reponse = vbNo) Then installphp() End If

End If

1 réponse

boudzz Messages postés 9 Date d'inscription samedi 14 mai 2005 Statut Membre Dernière intervention 18 juin 2010
15 juin 2005 à 10:38
J'ai résolu mon problème (apparemment avec set...?..) :

Voici le script après modifications



Const HKLM = &H80000002

chemin = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

'definition de requête wmi

sComputer = "." ' use "." for local computer

Set oWmi = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\" _

& sComputer & "\root\cimv2")



'definition des objets vbscripts

Set Fso = CreateObject("Scripting.FileSystemObject")

Set WshShell = CreateObject("WScript.Shell")

Set oReg = GetObject("winmgmts:root\default:StdRegProv")

Set WshNetwork = CreateObject("WScript.Network")



UserName =WshNetwork.UserName



Dim SubKey, arrSubKeys, Display

Dim ma_comparaison, php, objProcess, colProcessList, NomUser

Dim Key(), affiche(), version(), I, toto



'Il faut exécuter le package php ; Le problème vient du fait qu on ne connait pas la lettre du lecteur de

'cd pour notre chemin -> recherche de fichier "at-collab" : for each fso.drive...

WshShell.Run(CHR(34) & "C:/Installs/php5/msi-php/PHP5.msi" & CHR(34))



'------------------------------ tempo fenetre php ------------------------------

'tempo fenetre php

wscript.sleep(3000)

do

Set colProcessList = oWmi.ExecQuery _

("Select * from Win32_Process Where Name = 'msiexec.exe'")

For Each objProcess in colProcessList

Toto = objProcess.GetOwner(NomUser)

If NomUser = UserName Then wscript.sleep(500) End If

Next

loop while (colProcessList.count >= 2)



wscript.sleep(1000)

'-------------------------------------------------------------------------------



'Vérifions que notre utilisateur a installé php



'Enumération des clés (logiciels installés sur l ordi) dans "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

oReg.EnumKey HKLM, chemin, arrSubKeys

'initialisation de I

I = 0



For Each SubKey In arrSubKeys

ReDim Preserve Key(I)

ReDim Preserve affiche(I)

Key(I) = SubKey

oReg.GetStringValue HKLM, chemin & "" & SubKey, "DisplayName", Display

affiche(I) = Display

' Test de présence de php

php = LCase(left(affiche(I),3))

ma_comparaison = StrComp(php, "php", 1)

if (ma_comparaison = 0) then

GinstallePHP = 1

phpinstalle = 1

MsgBox " PHP a été installé avec succès :)", vbOKOnly + vbDefaultButton1 + vbInformation, ""

WshShell.Run(CHR(34) & "C:/php5conf.vbs" & CHR(34))

End If

I = I + 1

Next



If GinstallePHP = 0 Then

Reponse = MsgBox(" Vous n'avez pas installez PHP !
Etes-vous sûr de vouloir continuer ?", vbYesNo + vbDefaultButton1 +
vbCritical, "Attention !")

If (Reponse = vbNo) Then installphp() End If

End If
3
Rejoignez-nous