Example #1
0
        //will return -1 (uint.MaxValue == -1 as a signed integer) if it fails.
        public static uint RunThread(IntPtr hProcess, IntPtr lpStartAddress, IntPtr lpParam, int timeout = 1000)
        {
            uint dwThreadRet = uint.MaxValue;

            IntPtr hThread = PInvoke.CreateRemoteThread(hProcess, 0, 0, lpStartAddress, lpParam, 0, 0);

            if (hThread == IntPtr.Zero)
            {
                return(dwThreadRet);
            }

            if (PInvoke.WaitForSingleObject(hThread, timeout) == 0x0L) //wait for a response
            {
                PInvoke.GetExitCodeThread(hThread, out dwThreadRet);
            }

            return(dwThreadRet);
        }