|
using System;
namespace StartSuspended
{
class ProcessLauncher
{
IntPtr ThreadHandle = IntPtr.Zero;
public bool LaunchProcessSuspended(string processpath, int initialResumeTime, out uint PID)
{
STARTUPINFO si = new STARTUPINFO();
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
bool success = NativeMethods.CreateProcess(processpath, null, IntPtr.Zero, IntPtr.Zero, false, ProcessCreationFlags.CREATE_SUSPENDED, IntPtr.Zero, null, ref si, out pi);
ThreadHandle = pi.hThread;
PID = pi.dwProcessId;
if (initialResumeTime > 0)
{
NativeMethods.ResumeThread(ThreadHandle);
System.Threading.Thread.Sleep(initialResumeTime);
NativeMethods.SuspendThread(ThreadHandle);
}
return success;
}
public void ResumeProcess()
{
NativeMethods.ResumeThread(ThreadHandle);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.