mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Close process query handles
This commit is contained in:
1 parent
df9ab302ca
commit
2b29c15cf1
2 files changed
+36
-9
No files matched your search
@@ -69,6 +69,10 @@ public static unsafe partial class ProcessMonitor
|
||||
[LibraryImport("kernel32.dll")]
|
||||
private static partial nint OpenProcess(ProcessAccessFlags processAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int processId);
|
||||
|
||||
[LibraryImport("kernel32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool CloseHandle(nint hObject);
|
||||
|
||||
[Flags]
|
||||
private enum ProcessAccessFlags : uint
|
||||
{
|
||||
@@ -190,11 +194,20 @@ public static unsafe partial class ProcessMonitor
|
||||
{
|
||||
int capacity = byte.MaxValue;
|
||||
char[] buffer = new char[capacity];
|
||||
nint ptr = OpenProcess(ProcessAccessFlags.QueryLimitedInformation, false, processId);
|
||||
nint processHandle = OpenProcess(ProcessAccessFlags.QueryLimitedInformation, false, processId);
|
||||
if (processHandle == nint.Zero)
|
||||
return string.Empty;
|
||||
|
||||
return QueryFullProcessImageName(ptr, 0, buffer, ref capacity)
|
||||
? new string(buffer, 0, capacity)
|
||||
: string.Empty;
|
||||
try
|
||||
{
|
||||
return QueryFullProcessImageName(processHandle, 0, buffer, ref capacity)
|
||||
? new string(buffer, 0, capacity)
|
||||
: string.Empty;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseHandle(processHandle);
|
||||
}
|
||||
}
|
||||
|
||||
// This function generates the short form of process name.
|
||||
@@ -228,4 +241,4 @@ public static unsafe partial class ProcessMonitor
|
||||
private static uint GetEstimatedBufferSize(uint actualSize) => actualSize + (1024 * 10);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user