Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ StartWithCreateProcess()

unsafe bool System.Diagnostics.Process.StartWithCreateProcess ( ProcessStartInfo startInfo)
inlineprivate

Definition at line 1739 of file Process.cs.

1740 {
1744 global::Interop.Kernel32.STARTUPINFO lpStartupInfo = default(global::Interop.Kernel32.STARTUPINFO);
1745 global::Interop.Kernel32.PROCESS_INFORMATION lpProcessInformation = default(global::Interop.Kernel32.PROCESS_INFORMATION);
1746 global::Interop.Kernel32.SECURITY_ATTRIBUTES procSecAttrs = default(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
1755 {
1756 try
1757 {
1758 lpStartupInfo.cb = sizeof(global::Interop.Kernel32.STARTUPINFO);
1759 if (startInfo.RedirectStandardInput || startInfo.RedirectStandardOutput || startInfo.RedirectStandardError)
1760 {
1761 if (startInfo.RedirectStandardInput)
1762 {
1764 }
1765 else
1766 {
1767 childHandle = new SafeFileHandle(global::Interop.Kernel32.GetStdHandle(-10), ownsHandle: false);
1768 }
1769 if (startInfo.RedirectStandardOutput)
1770 {
1772 }
1773 else
1774 {
1775 childHandle2 = new SafeFileHandle(global::Interop.Kernel32.GetStdHandle(-11), ownsHandle: false);
1776 }
1777 if (startInfo.RedirectStandardError)
1778 {
1780 }
1781 else
1782 {
1783 childHandle3 = new SafeFileHandle(global::Interop.Kernel32.GetStdHandle(-12), ownsHandle: false);
1784 }
1785 lpStartupInfo.hStdInput = childHandle.DangerousGetHandle();
1786 lpStartupInfo.hStdOutput = childHandle2.DangerousGetHandle();
1787 lpStartupInfo.hStdError = childHandle3.DangerousGetHandle();
1789 }
1790 int num = 0;
1791 if (startInfo.CreateNoWindow)
1792 {
1793 num |= 0x8000000;
1794 }
1795 string text = null;
1796 if (startInfo._environmentVariables != null)
1797 {
1798 num |= 0x400;
1799 text = GetEnvironmentVariablesBlock(startInfo._environmentVariables);
1800 }
1801 string text2 = startInfo.WorkingDirectory;
1802 if (text2.Length == 0)
1803 {
1804 text2 = null;
1805 }
1806 int num2 = 0;
1807 bool flag;
1808 if (startInfo.UserName.Length != 0)
1809 {
1810 if (startInfo.Password != null && startInfo.PasswordInClearText != null)
1811 {
1813 }
1814 global::Interop.Advapi32.LogonFlags logonFlags = (global::Interop.Advapi32.LogonFlags)0;
1815 if (startInfo.LoadUserProfile)
1816 {
1817 logonFlags = global::Interop.Advapi32.LogonFlags.LOGON_WITH_PROFILE;
1818 }
1819 fixed (char* ptr = startInfo.PasswordInClearText ?? string.Empty)
1820 {
1821 fixed (char* ptr2 = text)
1822 {
1823 fixed (char* cmdLine = &commandLine.GetPinnableReference(terminate: true))
1824 {
1826 try
1827 {
1828 flag = global::Interop.Advapi32.CreateProcessWithLogonW(startInfo.UserName, startInfo.Domain, (intPtr != IntPtr.Zero) ? intPtr : ((IntPtr)ptr), logonFlags, null, cmdLine, num, (IntPtr)ptr2, text2, ref lpStartupInfo, ref lpProcessInformation);
1829 if (!flag)
1830 {
1832 }
1833 }
1834 finally
1835 {
1836 if (intPtr != IntPtr.Zero)
1837 {
1839 }
1840 }
1841 }
1842 }
1843 }
1844 }
1845 else
1846 {
1847 fixed (char* ptr3 = text)
1848 {
1849 fixed (char* lpCommandLine = &commandLine.GetPinnableReference(terminate: true))
1850 {
1851 flag = global::Interop.Kernel32.CreateProcess(null, lpCommandLine, ref procSecAttrs, ref procSecAttrs, bInheritHandles: true, num, (IntPtr)ptr3, text2, ref lpStartupInfo, ref lpProcessInformation);
1852 if (!flag)
1853 {
1855 }
1856 }
1857 }
1858 }
1859 if (lpProcessInformation.hProcess != IntPtr.Zero && lpProcessInformation.hProcess != new IntPtr(-1))
1860 {
1862 }
1863 if (lpProcessInformation.hThread != IntPtr.Zero && lpProcessInformation.hThread != new IntPtr(-1))
1864 {
1865 global::Interop.Kernel32.CloseHandle(lpProcessInformation.hThread);
1866 }
1867 if (!flag)
1868 {
1869 string errorMessage = ((num2 == 193 || num2 == 216) ? System.SR.InvalidApplication : GetErrorMessage(num2));
1871 }
1872 }
1873 finally
1874 {
1875 childHandle?.Dispose();
1876 childHandle2?.Dispose();
1877 childHandle3?.Dispose();
1878 }
1879 }
1880 if (startInfo.RedirectStandardInput)
1881 {
1882 Encoding encoding = startInfo.StandardInputEncoding ?? GetEncoding((int)global::Interop.Kernel32.GetConsoleCP());
1883 _standardInput = new StreamWriter(new FileStream(parentHandle, FileAccess.Write, 4096, isAsync: false), encoding, 4096);
1885 }
1886 if (startInfo.RedirectStandardOutput)
1887 {
1888 Encoding encoding2 = startInfo.StandardOutputEncoding ?? GetEncoding((int)global::Interop.Kernel32.GetConsoleOutputCP());
1890 }
1891 if (startInfo.RedirectStandardError)
1892 {
1893 Encoding encoding3 = startInfo.StandardErrorEncoding ?? GetEncoding((int)global::Interop.Kernel32.GetConsoleOutputCP());
1895 }
1896 commandLine.Dispose();
1897 if (safeProcessHandle.IsInvalid)
1898 {
1899 return false;
1900 }
1903 return true;
1904 }
static string GetEnvironmentVariablesBlock(IDictionary< string, string > sd)
Definition Process.cs:2033
void SetProcessHandle(SafeProcessHandle processHandle)
Definition Process.cs:1175
static readonly object s_createProcessLock
Definition Process.cs:176
static void BuildCommandLine(ProcessStartInfo startInfo, ref System.Text.ValueStringBuilder commandLine)
Definition Process.cs:1912
StreamReader _standardError
Definition Process.cs:156
void CreatePipe(out SafeFileHandle parentHandle, out SafeFileHandle childHandle, bool parentInputs)
Definition Process.cs:2003
StreamWriter _standardInput
Definition Process.cs:154
static Win32Exception CreateExceptionForErrorStartingProcess(string errorMessage, int errorCode, string fileName, string workingDirectory)
Definition Process.cs:1520
void SetProcessId(int processId)
Definition Process.cs:1185
StreamReader _standardOutput
Definition Process.cs:152
static string GetErrorMessage(int error)
Definition Process.cs:2048
static Encoding GetEncoding(int codePage)
Definition Process.cs:1906
static unsafe void ZeroFreeGlobalAllocUnicode(IntPtr s)
Definition Marshal.cs:1522
static IntPtr SecureStringToGlobalAllocUnicode(SecureString s)
Definition Marshal.cs:1284
static void InitHandle(SafeHandle safeHandle, IntPtr handle)
Definition Marshal.cs:1562
static string CantSetDuplicatePassword
Definition SR.cs:92
static string InvalidApplication
Definition SR.cs:58
Definition SR.cs:7

References System.Diagnostics.Process._standardError, System.Diagnostics.Process._standardInput, System.Diagnostics.Process._standardOutput, System.Diagnostics.Process.BuildCommandLine(), System.SR.CantSetDuplicatePassword, System.Diagnostics.Process.CreateExceptionForErrorStartingProcess(), System.Diagnostics.Process.CreatePipe(), System.Runtime.Serialization.Dictionary, System.Diagnostics.Process.GetEncoding(), System.Diagnostics.Process.GetEnvironmentVariablesBlock(), System.Diagnostics.Process.GetErrorMessage(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), System.Runtime.InteropServices.Marshal.InitHandle(), System.SR.InvalidApplication, System.Diagnostics.Process.s_createProcessLock, System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocUnicode(), System.Diagnostics.Process.SetProcessHandle(), System.Diagnostics.Process.SetProcessId(), System.text, System.IntPtr.Zero, and System.Runtime.InteropServices.Marshal.ZeroFreeGlobalAllocUnicode().

Referenced by System.Diagnostics.Process.StartCore().