FILETIME,
lpUserTime
As
FILETIME)
As
Long
Private
Declare
Function
FileTimeToSystemTime
Lib
"kernel32"
(lpFileTime
As
FILETIME,
lpSystemTime
As
SYSTEMTIME)
As
Long
Private
Type
FILETIME
'
8
Bytes
dwLowDateTime
As
Long
dwHighDateTime
As
Long
End
Type
Private
Type
SYSTEMTIME
'
16
Bytes
wYear
As
Integer
wMonth
As
Integer
wDayOfWeek
As
Integer
wDay
As
Integer
wHour
As
Integer
wMinute
As
Integer
wSecond
As
Integer
wMilliseconds
As
Integer
End
Type
'Private
Const
STANDARD_RIGHTS_REQUIRED
=
&HF0000
Private
Const
SYNCHRONIZE
=
&H100000
'Public
Const
SPECIFIC_RIGHTS_ALL
=
&HFFFF
Const
STANDARD_RIGHTS_REQUIRED
=
&HF0000
Private
Const
PROCESS_ALL_ACCESS
=
STANDARD_RIGHTS_REQUIRED
Or
SYNCHRONIZE
Or
&HFFF
Function
GetCpuTime(PID
As
Long)
As
String
Dim
lpCreateionTime
As
FILETIME,
lpExitTime
As
FILETIME,
lpKernelTime
As
FILETIME
Dim
lpUserTime
As
FILETIME,
CPUtime
As
FILETIME,
SysTime
As
SYSTEMTIME
GetProcessTimes
OpenProcess(PROCESS_ALL_ACCESS,
False,
PID),
lpCreateionTime,
lpExitTime,
lpKernelTime,
lpUserTime
CPUtime.dwHighDateTime
=
lpKernelTime.dwHighDateTime
+
lpUserTime.dwHighDateTime
CPUtime.dwLowDateTime
=
lpKernelTime.dwLowDateTime
+
lpUserTime.dwLowDateTime
FileTimeToSystemTime
CPUtime,
SysTime
GetCpuTime
=
(SysTime.wHour
&
":"
&
SysTime.wMinute
&
":"
&
SysTime.wSecond)
End
Function
上面是获取某一程序CPU时间的函数
应该可以直接用了
下面是获取某一程序占用内存的函数,还少了一些API函数和常数值申明
实在太困了
自己去找找吧
Public
Type
PROCESS_MEMORY_COUNTERS
cb
As
Long
PageFaultCount
As
Long
PeakWorkingSetSize
As
Long
WorkingSetSize
As
Long
QuotaPeakPagedPoolUsage
As
Long
QuotaPagedPoolUsage
As
Long
QuotaPeakNonPagedPoolUsage
As
Long
QuotaNonPagedPoolUsage
As
Long
PagefileUsage
As
Long
PeakPagefileUsage
As
Long
End
Type
Public
Function
GetMemory(PID
As
Long)
As
Long
Dim
pmc
As
PROCESS_MEMORY_COUNTERS
Dim
lret
As
Long,
ID
As
Long
id
=
OpenProcess(PROCESS_QUERY_INFORMATION
Or
PROCESS_VM_READ,
0,
PID)
pmc.cb
=
LenB(pmc)
lret
=
GetProcessMemoryInfo(id,
pmc,
pmc.cb)
GetMemory
=
pmc.WorkingSetSize
/
1024
End
FunctionTop