Example #1
0
        public static bool WinExecAndWait(string cmd, uint timeout)
        {
            var startupInfo = new Win32Import.StartupInfo();

            startupInfo.cb = (uint)Marshal.SizeOf(startupInfo);
            var processInfo = new Win32Import.Process_Information();

            Win32Import.Win32Bool r =
                Win32Import.CreateProcess(null, cmd.ToCharArray(),
                                          IntPtr.Zero, IntPtr.Zero, 0, 0, null, null, ref startupInfo, ref processInfo);
            if (r == Win32Import.Win32Bool.False)
            {
                return(false);
            }
            Win32Import.WaitForSingleObject(processInfo.hProcess, timeout);
            Win32Import.CloseHandle(processInfo.hThread);
            Win32Import.CloseHandle(processInfo.hProcess);
            return(true);
        }
Example #2
0
 public static bool WinExecAndWait(string cmd, uint timeout)
 {
     var startupInfo = new Win32Import.StartupInfo();
     startupInfo.cb = (uint)Marshal.SizeOf(startupInfo);
     var processInfo = new Win32Import.Process_Information();
     Win32Import.Win32Bool r =
         Win32Import.CreateProcess(null, cmd.ToCharArray(),
         IntPtr.Zero, IntPtr.Zero, 0, 0, null, null, ref startupInfo, ref processInfo);
     if (r == Win32Import.Win32Bool.False) return false;
     Win32Import.WaitForSingleObject(processInfo.hProcess, timeout);
     Win32Import.CloseHandle(processInfo.hThread);
     Win32Import.CloseHandle(processInfo.hProcess);
     return true;
 }