cs_JMO
Messages postés
1854
Date d'inscription
jeudi 23 mai 2002
Statut
Membre
Dernière intervention
24 juin 2018
27
7 oct. 2006 à 14:12
Bonjour,
Il y a simple avec WMI.
Exemple avec process Excel.
Option Explicit
Dim strComputer,objWMIService,colProcesses,objProcess,ProcessTime,strCreationDate,user,Domain,strOwner,h,m,s,chaine
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process where Name='EXCEL.EXE' ")
Chaine="Process |Creation Date Time |Handles|Threads|Owner |Priority|MemoryUsage|MaxMemUsage|MemRequired|MaxMemRequi| Swap| Max Swap|CPU time|PID |PFaults|Path" & vbCrLf
For Each objProcess in colProcesses
If objProcess.GetOwner ( User, Domain ) = 0 Then
strOwner= Domain & "" & User
Else
strOwner= Domain & "" & user 'strOwner="Unknown"
End If
ProcessTime=(CSng(objProcess.KernelModeTime) + CSng(objProcess.UserModeTime)) / 10000000
h=right("0" & fix(ProcessTime/60/60),2)
ProcessTime=ProcessTime-h*60*60
m=right("0" & fix(ProcessTime/60),2)
s=Right("0" & round(ProcessTime-m*60),2)
strCreationDate=Mid(objProcess.CreationDate,7,2) & "/" & Mid(objProcess.CreationDate,5,2) & "/" & Left(objProcess.CreationDate,4) & " " & Mid(objProcess.CreationDate,9,2) & ":" & Mid(objProcess.CreationDate,11,2) & ":" & Mid(objProcess.CreationDate,13,2)
If strCreationDate="// ::" Then strCreationDate=Space(19)
Chaine=Chaine & Left(objProcess.Name & space(8),12) & "|" _
& strCreationDate & "|" & Right(Space(6) & objProcess.HandleCount,7) & "|" _
& Right(Space(6) & objProcess.ThreadCount,7) & "|" _
& Left(strOwner & space(14),19) & "|" _
& Left(objProcess.Priority & Space(7),8) & "|" _
& Right(Space(10) & objProcess.PageFileUsage ,11) & "|" _
& Right(Space(10) & objProcess.PeakPageFileUsage ,11) & "|" _
& Right(Space(8) & objProcess.WorkingSetSize ,11) & "|" _
& Right(Space(8) & objProcess.PeakWorkingSetSize ,11) & "|" _
& Right(Space(10) & objProcess.VirtualSize ,11) & "|" _
& Right(Space(10) & objProcess.PeakVirtualSize ,11) & "|" _
& h & ":" & m & ":" & s & "|" _
& Left(objProcess.ProcessID & space(3),4) & "|" _
& Right(Space(6) & objProcess.PageFaults ,7) & "|" & objProcess.ExecutablePath
Chaine=Chaine & vbCrLf
'If objProcess.Name = "EXCEL.EXE" Then MsgBox objProcess.Name & " " & objProcess.VirtualSize
Next
Set objWMIService = Nothing
Set colProcesses = Nothing
wscript.echo chaine
jean-marc