Пример #1
0
        public static NativeProcess CreateProcess(string applicationName, string commandLine, CreateProcessFlags flags, StartupInfoW startupInfo, ProcThreadAttributeList atts, string currentDirectory, out NativeThread firstThread)
        {
            if ((flags & ~SupportedCreateProcessFlags) != 0)
            {
                throw new ArgumentException("Unsupported CreateProcessFlags given!");
            }
            if ((startupInfo.dwFlags & ~SupportedStartupInfoFlags) != 0)
            {
                throw new ArgumentException("Unsupported StartupInfoFlags given");
            }
            if (atts.IsDisposed)
            {
                throw new ObjectDisposedException("Atts");
            }

            StartupInfoExW startupInfoEx = new StartupInfoExW(startupInfo, atts);

            flags |= CreateProcessFlags.ExtendedStartupInfoPresent;

            return(CreateProcessInternal(applicationName, commandLine, flags, startupInfoEx, currentDirectory, out firstThread));
        }
Пример #2
0
        private static unsafe NativeProcess CreateProcessInternal(string applicationName, string commandLine, CreateProcessFlags flags, StartupInfoExW startupInfo, string currentDirectory, out NativeThread firstThread)
        {
            ProcessInformation processInfo;

            bool success = CreateProcessW(applicationName, commandLine, null, null, false, (UInt32)flags, null, currentDirectory, &startupInfo.StartupInfo, &processInfo);

            if (!success)
            {
                throw new Win32Exception();
            }

            firstThread = new NativeThread(new SafeThreadHandle(processInfo.hThread));
            return(new NativeProcess(new SafeProcessHandle(processInfo.hProcess)));
        }