Exemplo n.º 1
0
 public static extern bool CreateProcess
     (string lpApplicationName,
     string lpCommandLine,
     ref SecurityAttributes lpProcessAttributes,
     ref SecurityAttributes lpThreadAttributes,
     bool bInheritHandles,
     Int32 dwCreationFlags,
     IntPtr lpEnvironment,
     string lpCurrentDirectory,
     [In] ref StartupInfo lpStartupInfo,
     out ProcessInformation lpProcessInformation);
Exemplo n.º 2
0
        public static ProcessStartResult StartProcess(string exe,
                                                      string[] args    = null,
                                                      bool isHidden    = false,
                                                      bool waitForExit = false,
                                                      uint waitTimeout = 0)
        {
            string command;

            var startupInfo = CreateStartupInfo(exe, args, isHidden, out command);

            ProcessInformation processInfo;

            var processSecAttributes = new SecurityAttributes();

            processSecAttributes.Length = Marshal.SizeOf(processSecAttributes);

            var threadSecAttributes = new SecurityAttributes();

            threadSecAttributes.Length = Marshal.SizeOf(threadSecAttributes);

            CreationFlags creationFlags = 0;

            if (isHidden)
            {
                creationFlags = CreationFlags.CreateNoWindow;
            }

            var started = Win32Api.CreateProcess(exe,
                                                 command,
                                                 ref processSecAttributes,
                                                 ref threadSecAttributes,
                                                 false,
                                                 Convert.ToInt32(creationFlags),
                                                 IntPtr.Zero,
                                                 null,
                                                 ref startupInfo,
                                                 out processInfo);


            var result = CreateProcessStartResult(waitForExit, waitTimeout, processInfo, started);

            return(result);
        }
Exemplo n.º 3
0
        public static ProcessStartResult StartProcess(string exe,
                                                      string[] args = null,
                                                      bool isHidden = false,
                                                      bool waitForExit = false,
                                                      uint waitTimeout = 0)
        {
            string command;

            var startupInfo = CreateStartupInfo(exe, args, isHidden, out command);

            ProcessInformation processInfo;

            var processSecAttributes = new SecurityAttributes();

            processSecAttributes.Length = Marshal.SizeOf(processSecAttributes);

            var threadSecAttributes = new SecurityAttributes();

            threadSecAttributes.Length = Marshal.SizeOf(threadSecAttributes);

            CreationFlags creationFlags = 0;

            if (isHidden)
            {
                creationFlags = CreationFlags.CreateNoWindow;
            }

            var started = Win32Api.CreateProcess(exe,
                                                    command,
                                                    ref processSecAttributes,
                                                    ref threadSecAttributes,
                                                    false,
                                                    Convert.ToInt32(creationFlags),
                                                    IntPtr.Zero,
                                                    null,
                                                    ref startupInfo,
                                                    out processInfo);

            var result = CreateProcessStartResult(waitForExit, waitTimeout, processInfo, started);

            return result;
        }