Get process GDI object count
I'm looking to get the count of GDIObjects of certain processes.
Using Windows XP it was possible with user32.dll's getGUIResources()
, but on Windows Vista and -7 it returns 0
for processes running under ..\System
.
How to get the GDI 开发者_如何学运维object count?
Try this code. It works for me on Windows 7. I thought: "If task manager can do it, then I can do it". I'm not sure if it requires administrative privileges, but I have tested with.
In the example I get information from winlogon.exe which runs under SYSTEM credentials.
Output on my machine:
Process ID: 584
Process handle: 0x00000198
GDI objects: 6
which fits with what task manager was showing.
#RequireAdmin
#include <WinAPI.au3>
Const $PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
; Get ID to process
$id = ProcessExists("winlogon.exe")
If @error Then
ConsoleWrite("Error in ProcessExists: " & @error & @CRLF)
Exit
EndIf
ConsoleWrite("Process ID: " & $id & @CRLF)
; Get handle to process from the ID
$handle = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, False, $id)
If @error Then
ConsoleWrite("Error in _WinAPI_OpenProcess: " & @error & @CRLF)
Exit
EndIf
ConsoleWrite("Process handle: " & $handle & @CRLF)
; Get number of GDI objects via GetGuiResources
$gdiCount = _WinAPI_GetGuiResources(0, $handle)
If @error Then
ConsoleWrite("Error in _WinAPI_GetGuiResources: " & @error & @CRLF)
Exit
EndIf
ConsoleWrite("GDI objects: " & $gdiCount & @CRLF)
; Close handle to process
_WinAPI_CloseHandle($handle)
Probably something about access rights, your script not being able to access processes with higher privileges. I'm not sure here though, but give this a try: Run your script with administrator privileges by adding this to your script:
#RequireAdmin
精彩评论