mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Merge pull request #1043 from nullif/enum-processes-fix
EnumProcesses returns the byte count not length
This commit is contained in:
@@ -789,18 +789,18 @@ namespace Squirrel
|
||||
{
|
||||
public static List<Tuple<string, int>> EnumerateProcesses()
|
||||
{
|
||||
int length = 0;
|
||||
int bytesReturned = 0;
|
||||
var pids = new int[2048];
|
||||
|
||||
fixed(int* p = pids) {
|
||||
if (!NativeMethods.EnumProcesses((IntPtr)p, sizeof(int) * pids.Length, out length)) {
|
||||
if (!NativeMethods.EnumProcesses((IntPtr)p, sizeof(int) * pids.Length, out bytesReturned)) {
|
||||
throw new Win32Exception("Failed to enumerate processes");
|
||||
}
|
||||
|
||||
if (length < 1) throw new Exception("Failed to enumerate processes");
|
||||
if (bytesReturned < 1) throw new Exception("Failed to enumerate processes");
|
||||
}
|
||||
|
||||
return Enumerable.Range(0, length)
|
||||
return Enumerable.Range(0, bytesReturned / sizeof(int))
|
||||
.Where(i => pids[i] > 0)
|
||||
.Select(i => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user