@@ -375,32 +375,34 @@ EXTERN_DLL_EXPORT VOID __stdcall ControlRemoteProcess(HANDLE process, ControlRem
375375 if (action == ControlRemoteProcessAction::Suspend || action == ControlRemoteProcessAction::Resume)
376376 {
377377 auto processId = GetProcessId (process);
378-
379- auto handle = CreateToolhelp32Snapshot (TH32CS_SNAPTHREAD, 0 );
380- if (handle != INVALID_HANDLE_VALUE)
378+ if (processId != 0 )
381379 {
382- auto fn = action == ControlRemoteProcessAction::Suspend ? SuspendThread : ResumeThread;
383-
384- THREADENTRY32 te32 = {};
385- te32.dwSize = sizeof (THREADENTRY32);
386- if (Thread32First (handle, &te32))
380+ auto handle = CreateToolhelp32Snapshot (TH32CS_SNAPTHREAD, 0 );
381+ if (handle != INVALID_HANDLE_VALUE)
387382 {
388- do
383+ auto fn = action == ControlRemoteProcessAction::Suspend ? SuspendThread : ResumeThread;
384+
385+ THREADENTRY32 te32 = {};
386+ te32.dwSize = sizeof (THREADENTRY32);
387+ if (Thread32First (handle, &te32))
389388 {
390- if (te32. th32OwnerProcessID == processId)
389+ do
391390 {
392- auto threadHandle = OpenThread (THREAD_SUSPEND_RESUME, FALSE , te32.th32ThreadID );
393- if (threadHandle)
391+ if (te32.th32OwnerProcessID == processId)
394392 {
395- fn (threadHandle);
393+ auto threadHandle = OpenThread (THREAD_SUSPEND_RESUME, FALSE , te32.th32ThreadID );
394+ if (threadHandle)
395+ {
396+ fn (threadHandle);
396397
397- CloseHandle (threadHandle);
398+ CloseHandle (threadHandle);
399+ }
398400 }
399- }
400- } while (Thread32Next (handle, &te32));
401- }
401+ } while (Thread32Next (handle, &te32));
402+ }
402403
403- CloseHandle (handle);
404+ CloseHandle (handle);
405+ }
404406 }
405407 }
406408 else if (action == ControlRemoteProcessAction::Terminate)
0 commit comments