public static extern bool CreateProcess(string lpApplicationName,
                                         string lpCommandLine, IntPtr lpProcessAttributes,
                                         IntPtr lpThreadAttributes,
                                         bool bInheritHandles, ProcessCreationFlags dwCreationFlags,
                                         IntPtr lpEnvironment, string lpCurrentDirectory,
                                         ref Startupinfo lpStartupInfo,
                                         out ProcessInformation lpProcessInformation);
Пример #2
0
        public Process Launch(LaunchConfiguration launchConfig, bool startSuspended = false, OnSuspendedLaunch handler = null)
        {
            if (startSuspended)
            {
                var si      = new Startupinfo();
                var pi      = new ProcessInformation();
                var success = NativeMethods.CreateProcess(launchConfig.DragonNestExePath,
                                                          "\"dragonnest.exe\" " + launchConfig.CommandLineParams,
                                                          IntPtr.Zero,
                                                          IntPtr.Zero,
                                                          false,
                                                          ProcessCreationFlags.CREATE_SUSPENDED,
                                                          IntPtr.Zero,
                                                          Directory.GetParent(launchConfig.DragonNestExePath).FullName,
                                                          ref si,
                                                          out pi);

                if (success)
                {
                    handler?.Invoke(pi);
                    NativeMethods.ResumeThread(pi.hThread);
                    return(Process.GetProcessById((int)pi.dwProcessId));
                }
            }

            var proc = new Process
            {
                StartInfo =
                {
                    WorkingDirectory = Directory.GetParent(launchConfig.DragonNestExePath).FullName,
                    FileName         = launchConfig.DragonNestExePath,
                    Arguments        = launchConfig.CommandLineParams
                }
            };

            proc.Start();
            return(proc);
        }