Inheritance: System.SystemException
コード例 #1
0
		[Test] // ctor (string, Exception)
		public void Constructor3 ()
		{
			ExternalException ex;
			string msg = "ERROR";
			Exception inner = new Exception ();

			ex = new ExternalException (msg, inner);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#A1");
			Assert.AreSame (inner, ex.InnerException, "#A2");
			Assert.AreSame (msg, ex.Message, "#A3");

			ex = new ExternalException ((string) null, inner);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#B1");
			Assert.AreSame (inner, ex.InnerException, "#B2");
			Assert.IsNotNull (msg, ex.Message, "#B3");
			Assert.AreEqual (new ExternalException (null).Message, ex.Message, "#B4");

			ex = new ExternalException (msg, (Exception) null);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#C1");
			Assert.IsNull (ex.InnerException, "#C2");
			Assert.AreSame (msg, ex.Message, "#C3");

			ex = new ExternalException (string.Empty, (Exception) null);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#D1");
			Assert.IsNull (ex.InnerException, "#D2");
			Assert.IsNotNull (ex.Message, "#D3");
			Assert.AreEqual (string.Empty, ex.Message, "#D4");
		}
コード例 #2
0
		[Test] // ctor ()
		public void Constructor0 ()
		{
			ExternalException ex = new ExternalException ();
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#1");
			Assert.IsNull (ex.InnerException, "#2");
			Assert.IsNotNull (ex.Message, "#3");
			Assert.IsTrue (ex.Message.IndexOf (ex.GetType ().FullName) == -1, "#4");
		}
コード例 #3
0
        /// <summary>
        /// activex에서 넘어오는 에러 처리.
        /// </summary>
        /// <param name="ex"></param>
        private Exception ComException(System.Runtime.InteropServices.ExternalException ex, string Info)
        {
            Exception Ex;

            switch (ex.ErrorCode)
            {
            case -2147467259:                       //ProgramID가 잘못 지적 되어있거나, ItemId가 그룹에 등록 않되어 있을 경우
                if (Info == string.Empty)
                {
                    Ex = new Exception("Opc Open Error : ProramID를 찾지 못하였습니다. 설정 값을 확인 하여 주십시요", ex);
                }
                else
                if (this.bolOpcStatus)
                {
                    Ex = new Exception("Item Error : 해당 Item이 등록되어 있지 않습니다.(" + Info + ")", ex);
                }
                else
                {
                    Ex = new Exception("Opc와 연결이 끊어 졌습니다.", ex);
                }

                break;

            case -1073479673:
                if (this.bolOpcStatus)
                {
                    Ex = new Exception("Item Error : 해당 Item이 등록되어 있지 않습니다.(" + Info + ")", ex);
                }
                else
                {
                    Ex = new Exception("Opc와 연결이 끊어 졌습니다.", ex);
                }
                break;

            default:
                Ex = new Exception("Opc Open Error : " + ex.Message, ex);
                break;
            }

            return(Ex);
        }
コード例 #4
0
		[Test] // ctor (string)
		public void Constructor1 ()
		{
			ExternalException ex;
			string msg = "ERROR";

			ex = new ExternalException (msg);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#A1");
			Assert.IsNull (ex.InnerException, "#A2");
			Assert.AreSame (msg, ex.Message, "#A3");

			ex = new ExternalException ((string) null);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#B1");
			Assert.IsNull (ex.InnerException, "#B2");
			Assert.IsNotNull (msg, ex.Message, "#B3");
			Assert.IsTrue (ex.Message.IndexOf (ex.GetType ().FullName) != -1, "#B4");

			ex = new ExternalException (string.Empty);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#C1");
			Assert.IsNull (ex.InnerException, "#C2");
			Assert.IsNotNull (msg, ex.Message, "#C3");
			Assert.AreEqual (string.Empty, ex.Message, "#C4");
		}
コード例 #5
0
        // END - WHIDBEY ADDITIONS -->

        private static void ThrowIfFailed(int hr) {
            // 
            if (hr != 0) {
                ExternalException e = new ExternalException(SR.GetString(SR.ClipboardOperationFailed), hr);
                throw e;
            }
        }
コード例 #6
0
ファイル: ExceptionDispatchInfo.cs プロジェクト: Indifer/Test
		private static Exception SafeCreateMatroshika( ExternalException inner )
		{
			var result = GetMatroshika( inner );
			if ( result != null )
			{
				_exceptionHResultProperty.SetValue( result, Marshal.GetHRForException( inner ), null );
			}

			return result;
		}
コード例 #7
0
		public void TestExternalException()
		{
			var value = new ExternalException( "Message", 12345 );
			try
			{
				ExceptionDispatchInfo.Capture( value ).Throw();
			}
			catch ( ExternalException ex )
			{
				Assert.That( ex, Is.Not.SameAs( value ) );
				Assert.That( ex.ErrorCode, Is.EqualTo( value.ErrorCode ) );
			}
		}
コード例 #8
0
ファイル: Exceptions.cs プロジェクト: jcteague/ironruby
        public static ExternalException/*!*/ Factory(RubyClass/*!*/ self, int errorCode) {
            // TODO:
            var message = MutableString.Create("system error #" + errorCode);

            ExternalException result = new ExternalException(Errno.MakeMessage(ref message, "unknown error"));
            RubyExceptionData.InitializeException(result, message);
            return result;
        }
コード例 #9
0
ファイル: EmulatorHelper.cs プロジェクト: superyfwy/db4o
		public static bool IsIteratonFinishedException(ExternalException comException)
		{
			return comException.ErrorCode == ITERATION_FINISHED_HRESULT;
		}
コード例 #10
0
 protected static void NotImplemented()
 {
     ExternalException e = new ExternalException("Not implemented.", VSConstants.E_NOTIMPL);
     throw e;
 }
コード例 #11
0
ファイル: Exceptions.cs プロジェクト: rafacv/iron_languages
        public static ExternalException/*!*/ Factory(RubyClass/*!*/ self, [DefaultProtocol]MutableString message, int errorCode) {
            switch (errorCode) {
                // TODO:
                //case 0: return RubyExceptions.CreateNOERROR();
                //case 1: return RubyExceptions.CreateEPERM();
                //case 2: return RubyExceptions.CreateENOENT(); TODO: types don't match
                //case 3: return RubyExceptions.CreateESRCH();
                //case 4: return RubyExceptions.CreateEINTR();
                //case 5: return RubyExceptions.CreateEIO();
                //case 6: return RubyExceptions.CreateENXIO();
                //case 7: return RubyExceptions.CreateE2BIG();
                //case 8: return RubyExceptions.CreateENOEXEC(); 
                //case 9: return RubyExceptions.CreateEBADF();     TODO: types don't match
                //case 10: return new Errno.ChildError();
                //case 11: return RubyExceptions.CreateEAGAIN();
                //case 12: return RubyExceptions.CreateENOMEM();
                //case 13: return RubyExceptions.CreateEACCES();    TODO: types don't match
                //case 14: return RubyExceptions.CreateEFAULT();
                //case 15: break;
                //case 16: return RubyExceptions.CreateEBUSY();
                //case 17: return RubyExceptions.CreateEEXIST();    TODO: types don't match
                //case 18: return RubyExceptions.CreateEXDEV();
                //case 19: return RubyExceptions.CreateENODEV();
                //case 20: return RubyExceptions.CreateENOTDIR();
                //case 21: return RubyExceptions.CreateEISDIR();
                //case 22: return RubyExceptions.CreateEINVAL();    TODO: Types don't match
                //case 23: return RubyExceptions.CreateENFILE();
                //case 24: return RubyExceptions.CreateEMFILE();
                //case 25: return RubyExceptions.CreateENOTTY();
                //case 26: break;
                //case 27: return RubyExceptions.CreateEFBIG();
                //case 28: return RubyExceptions.CreateENOSPC();
                //case 29: return RubyExceptions.CreateESPIPE();
                //case 30: return RubyExceptions.CreateEROFS();
                //case 31: return RubyExceptions.CreateEMLINK();
                //case 32: return RubyExceptions.CreateEPIPE();
                //case 33: return RubyExceptions.CreateEDOM();
                //case 34: return RubyExceptions.CreateERANGE();
                //case 35: break;
                //case 36: return RubyExceptions.CreateEDEADLK();
                //case 37: break;
                //case 38: return RubyExceptions.CreateENAMETOOLONG();
                //case 39: return RubyExceptions.CreateENOLCK();
                //case 40: return RubyExceptions.CreateENOSYS();
                //case 41: return RubyExceptions.CreateENOTEMPTY();
                //case 42: return RubyExceptions.CreateEILSEQ();

                // case 10035: return RubyExceptions.CreateEWOULDBLOCK();
                // case 10036: return RubyExceptions.CreateEINPROGRESS();
                // case 10037: return RubyExceptions.CreateEALREADY();
                // case 10038: return RubyExceptions.CreateENOTSOCK();
                // case 10039: return RubyExceptions.CreateEDESTADDRREQ();
                // case 10040: return RubyExceptions.CreateEMSGSIZE();
                // case 10041: return RubyExceptions.CreateEPROTOTYPE();
                // case 10042: return RubyExceptions.CreateENOPROTOOPT();
                // case 10043: return RubyExceptions.CreateEPROTONOSUPPORT();
                // case 10044: return RubyExceptions.CreateESOCKTNOSUPPORT();
                // case 10045: return RubyExceptions.CreateEOPNOTSUPP();
                // case 10046: return RubyExceptions.CreateEPFNOSUPPORT();
                // case 10047: return RubyExceptions.CreateEAFNOSUPPORT();
                case 10048: return new Errno.AddressInUseError();
                // case 10049: return RubyExceptions.CreateEADDRNOTAVAIL();
                // case 10050: return RubyExceptions.CreateENETDOWN();
                // case 10051: return RubyExceptions.CreateENETUNREACH();
                // case 10052: return RubyExceptions.CreateENETRESET();
                case 10053: return new Errno.ConnectionAbortedError();
                case 10054: return new Errno.ConnectionResetError();
                // case 10055: return RubyExceptions.CreateENOBUFS();
                // case 10056: return RubyExceptions.CreateEISCONN();
                case 10057: return new Errno.NotConnectedError();
                // case 10058: return RubyExceptions.CreateESHUTDOWN();
                // case 10059: return RubyExceptions.CreateETOOMANYREFS();
                // case 10060: return RubyExceptions.CreateETIMEDOUT();
                case 10061: return new Errno.ConnectionRefusedError();
                // case 10062: return RubyExceptions.CreateELOOP();
                case 10064: return new Errno.HostDownError();
                // case 10065: return RubyExceptions.CreateEHOSTUNREACH();
                // case 10068: return RubyExceptions.CreateEUSERS();
                // case 10069: return RubyExceptions.CreateEDQUOT();
                // case 10070: return RubyExceptions.CreateESTALE();
                // case 10071: return RubyExceptions.CreateEREMOTE();
            }

#if SILVERLIGHT
            ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "Unknown Error"));
#else
            ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "Unknown Error"), errorCode);
#endif
            RubyExceptionData.InitializeException(result, message);
            return result;
        }
 protected static void NotImplemented()
 {
     ExternalException exception = new ExternalException(Res.GetString("NotImplemented"), -2147467263);
     throw exception;
 }
コード例 #13
0
 protected static ExternalException EFail(string msg)
 {
     ExternalException e = new ExternalException(msg, VSConstants.E_FAIL);
     throw e;
 }
 protected static ExternalException EFail(string msg)
 {
     ExternalException exception = new ExternalException(msg, -2147467259);
     throw exception;
 }
 protected static void NotImplemented()
 {
     ExternalException exception = new ExternalException(System.Windows.Forms.SR.GetString("UnsafeNativeMethodsNotImplemented"), -2147467263);
     throw exception;
 }
コード例 #16
0
ファイル: Exceptions.cs プロジェクト: jschementi/iron
 public static int Errno(ExternalException/*!*/ self) {
     return self.ErrorCode;
 }
コード例 #17
0
ファイル: Exceptions.cs プロジェクト: rafacv/iron_languages
 public static object Errno(ExternalException/*!*/ self) {
     return self.ErrorCode == int.MinValue ? (object)null : (object)self.ErrorCode;
 }
コード例 #18
0
        private static unsafe int ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, string cmd, string currentDir, TempFileCollection tempFiles, ref string outputName, ref string errorName, string trueCmdLine) {

            IntSecurity.UnmanagedCode.Demand();

            FileStream output;
            FileStream error;

            int retValue = 0;

            if (outputName == null || outputName.Length == 0)
                outputName = tempFiles.AddExtension("out");

            if (errorName == null || errorName.Length == 0)
                errorName = tempFiles.AddExtension("err");

            // Create the files
            output = CreateInheritedFile(outputName);
            error = CreateInheritedFile(errorName);

            bool success = false;
            SafeNativeMethods.PROCESS_INFORMATION pi = new SafeNativeMethods.PROCESS_INFORMATION();
            SafeProcessHandle procSH = new SafeProcessHandle();
            SafeThreadHandle threadSH = new SafeThreadHandle();
            SafeUserTokenHandle primaryToken = null;

            try {
                // Output the command line...
                StreamWriter sw = new StreamWriter(output, Encoding.UTF8);
                sw.Write(currentDir);
                sw.Write("> ");
                // 'true' command line is used in case the command line points to
                // a response file
                sw.WriteLine(trueCmdLine != null ? trueCmdLine : cmd);
                sw.WriteLine();
                sw.WriteLine();
                sw.Flush();

                NativeMethods.STARTUPINFO si = new NativeMethods.STARTUPINFO();

                si.cb = Marshal.SizeOf(si);
#if FEATURE_PAL
                si.dwFlags = NativeMethods.STARTF_USESTDHANDLES;
#else //!FEATURE_PAL
                si.dwFlags = NativeMethods.STARTF_USESTDHANDLES | NativeMethods.STARTF_USESHOWWINDOW;
                si.wShowWindow = NativeMethods.SW_HIDE;
#endif //!FEATURE_PAL
                si.hStdOutput = output.SafeFileHandle;
                si.hStdError = error.SafeFileHandle;
                si.hStdInput = new SafeFileHandle(UnsafeNativeMethods.GetStdHandle(NativeMethods.STD_INPUT_HANDLE), false);

                //
                // Prepare the environment
                //
#if PLATFORM_UNIX

                StringDictionary environment = new CaseSensitiveStringDictionary();

#else

                StringDictionary environment = new StringDictionary ();

#endif // PLATFORM_UNIX

                // Add the current environment
                foreach ( DictionaryEntry entry in Environment.GetEnvironmentVariables () )
                    environment[(string) entry.Key] = (string) entry.Value;

                // Add the flag to indicate restricted security in the process
                environment["_ClrRestrictSecAttributes"] = "1";

                #if DEBUG
                environment["OANOCACHE"] = "1";
                #endif

                // set up the environment block parameter
                byte[] environmentBytes = EnvironmentBlock.ToByteArray(environment, false);
                fixed (byte* environmentBytesPtr = environmentBytes) {
                    IntPtr environmentPtr = new IntPtr((void*)environmentBytesPtr);

                    if (userToken == null || userToken.IsInvalid) {
                        RuntimeHelpers.PrepareConstrainedRegions();
                        try {} finally {
                           success = NativeMethods.CreateProcess(
                                                       null,       // String lpApplicationName, 
                                                       new StringBuilder(cmd), // String lpCommandLine, 
                                                       null,       // SECURITY_ATTRIBUTES lpProcessAttributes, 
                                                       null,       // SECURITY_ATTRIBUTES lpThreadAttributes, 
                                                       true,       // bool bInheritHandles, 
                                                       0,          // int dwCreationFlags, 
                                                       environmentPtr, // IntPtr lpEnvironment, 
                                                       currentDir, // String lpCurrentDirectory, 
                                                       si,         // STARTUPINFO lpStartupInfo, 
                                                       pi);        // PROCESS_INFORMATION lpProcessInformation);
                            if ( pi.hProcess!= (IntPtr)0 && pi.hProcess!= (IntPtr)NativeMethods.INVALID_HANDLE_VALUE)
                                procSH.InitialSetHandle(pi.hProcess);  
                            if ( pi.hThread != (IntPtr)0 && pi.hThread != (IntPtr)NativeMethods.INVALID_HANDLE_VALUE)
                               threadSH.InitialSetHandle(pi.hThread);
                        }
                    }
                    else {
#if FEATURE_PAL
                        throw new NotSupportedException();
#else
                        success = SafeUserTokenHandle.DuplicateTokenEx(
                                                    userToken,
                                                    NativeMethods.TOKEN_ALL_ACCESS,
                                                    null,
                                                    NativeMethods.IMPERSONATION_LEVEL_SecurityImpersonation,
                                                    NativeMethods.TOKEN_TYPE_TokenPrimary,
                                                    out primaryToken
                                                    );


                        if (success) {
                            RuntimeHelpers.PrepareConstrainedRegions();
                            try {} finally {
                               success = NativeMethods.CreateProcessAsUser(
                                                           primaryToken,  // int token,
                                                           null,       // String lpApplicationName, 
                                                           cmd,        // String lpCommandLine, 
                                                           null,       // SECURITY_ATTRIBUTES lpProcessAttributes, 
                                                           null,       // SECURITY_ATTRIBUTES lpThreadAttributes, 
                                                           true,       // bool bInheritHandles, 
                                                           0,          // int dwCreationFlags, 
                                                           new HandleRef(null, environmentPtr), // IntPtr lpEnvironment, 
                                                           currentDir, // String lpCurrentDirectory, 
                                                           si,         // STARTUPINFO lpStartupInfo, 
                                                           pi);        // PROCESS_INFORMATION lpProcessInformation);
                               if ( pi.hProcess!= (IntPtr)0 && pi.hProcess!= (IntPtr)NativeMethods.INVALID_HANDLE_VALUE)
                                   procSH.InitialSetHandle(pi.hProcess);  
                               if ( pi.hThread != (IntPtr)0 && pi.hThread != (IntPtr)NativeMethods.INVALID_HANDLE_VALUE)
                                  threadSH.InitialSetHandle(pi.hThread);
                            }
                        }
#endif // !FEATURE_PAL
                    }
                }
            }
            finally {
                // Close the file handles
                if (!success && (primaryToken != null && !primaryToken.IsInvalid)) {
                    primaryToken.Close();
                    primaryToken = null;
                }

                output.Close();
                error.Close();
            }
            
            if (success) {

                try {
                    bool signaled;
                    ProcessWaitHandle pwh = null;
                    try {
                        pwh = new ProcessWaitHandle(procSH);
                        signaled = pwh.WaitOne(ProcessTimeOut, false);
                    } finally {
                        if (pwh != null)
                            pwh.Close();
                    }

                    // Check for timeout
                    if (!signaled) {
                        throw new ExternalException(SR.GetString(SR.ExecTimeout, cmd), NativeMethods.WAIT_TIMEOUT);
                    }

                    // Check the process's exit code
                    int status = NativeMethods.STILL_ACTIVE;
                    if (!NativeMethods.GetExitCodeProcess(procSH, out status)) {
                        throw new ExternalException(SR.GetString(SR.ExecCantGetRetCode, cmd), Marshal.GetLastWin32Error());
                    }

                    retValue = status;
                }
                finally {
                    procSH.Close();
                    threadSH.Close();
                    if (primaryToken != null && !primaryToken.IsInvalid)
                        primaryToken.Close();
                }
            }
            else {
                int err = Marshal.GetLastWin32Error();
                if (err == NativeMethods.ERROR_NOT_ENOUGH_MEMORY)
                    throw new OutOfMemoryException();

                Win32Exception win32Exception = new Win32Exception(err);
                ExternalException ex = new ExternalException(SR.GetString(SR.ExecCantExec, cmd), win32Exception);
                throw ex;
            }

            return retValue;
        }
コード例 #19
0
ファイル: Exceptions.cs プロジェクト: rafacv/iron_languages
        public static ExternalException/*!*/ Factory(RubyClass/*!*/ self, [DefaultProtocol]MutableString message) {
#if SILVERLIGHT
            ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "unknown error"));
#else
            ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "unknown error"), int.MinValue);
#endif
            RubyExceptionData.InitializeException(result, message);
            return result;
        }
コード例 #20
0
ファイル: UnsafeNativeMethods.cs プロジェクト: JianwenSun/cc
 protected static void NotImplemented() {
     ExternalException e = new ExternalException(SR.GetString(SR.UnsafeNativeMethodsNotImplemented), NativeMethods.E_NOTIMPL);
     throw e;
 }
コード例 #21
0
ファイル: Exceptions.cs プロジェクト: jcteague/ironruby
 public static ExternalException/*!*/ Factory(RubyClass/*!*/ self, [DefaultProtocol]MutableString message) {
     ExternalException result = new ExternalException(Errno.MakeMessage(ref message, "unknown error"));
     RubyExceptionData.InitializeException(result, message);
     return result;
 }
コード例 #22
0
 /// <summary>
 /// Request the exception message for BITS errors.
 /// </summary>
 /// <param name="exception">the exception thrown by the BITS system.</param>
 /// <returns>
 /// a string error description from the bits manager for the given exception.
 /// </returns>
 private static string GetExternalErrorMessage( ExternalException exception )
 {
     string message;
     try
     {
         message = BitsManagerAdapter.GetErrorDescription( exception.ErrorCode );
     }
     catch ( Exception )
     {
         message = exception.Message;
     }
     return message;
 }
コード例 #23
0
ファイル: UnsafeNativeMethods.cs プロジェクト: JianwenSun/cc
 protected static ExternalException EFail(string msg) {
     ExternalException e = new ExternalException(msg, NativeMethods.E_FAIL);
     throw e;
 }
コード例 #24
0
ファイル: ExceptionDispatchInfo.cs プロジェクト: Indifer/Test
			public WrapperExternalException( string message, ExternalException inner )
				: base( message, inner )
			{
				this.HResult = inner.ErrorCode;
			}
コード例 #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitsException"/> class.
 /// </summary>
 /// <param name="innerException">The inner exception.</param>
 public BitsException( ExternalException innerException )
     : base( GetExternalErrorMessage( innerException ), innerException )
 {
 }
コード例 #26
0
		[Test] // ctor (string, int)
		public void Constructor4 ()
		{
			ExternalException ex;
			string msg = "ERROR";

			ex = new ExternalException (msg, int.MinValue);
			Assert.AreEqual (int.MinValue, ex.ErrorCode, "#A1");
			Assert.IsNull (ex.InnerException, "#A2");
			Assert.AreSame (msg, ex.Message, "#A3");

			ex = new ExternalException ((string) null, int.MaxValue);
			Assert.AreEqual (int.MaxValue, ex.ErrorCode, "#B1");
			Assert.IsNull (ex.InnerException, "#B2");
			Assert.IsNotNull (msg, ex.Message, "#B3");
			Assert.AreEqual (new ExternalException (null).Message, ex.Message, "#B4");

			ex = new ExternalException (msg, 0);
			Assert.AreEqual (0, ex.ErrorCode, "#C1");
			Assert.IsNull (ex.InnerException, "#C2");
			Assert.AreSame (msg, ex.Message, "#C3");

			ex = new ExternalException (string.Empty, 0);
			Assert.AreEqual (0, ex.ErrorCode, "#D1");
			Assert.IsNull (ex.InnerException, "#D2");
			Assert.IsNotNull (ex.Message, "#D3");
			Assert.AreEqual (string.Empty, ex.Message, "#D4");
		}
コード例 #27
0
 private static void ThrowIfFailed(int hr)
 {
     if (hr != 0)
     {
         ExternalException exception = new ExternalException(System.Windows.Forms.SR.GetString("ClipboardOperationFailed"), hr);
         throw exception;
     }
 }
コード例 #28
0
 private static unsafe int ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, string cmd, string currentDir, TempFileCollection tempFiles, ref string outputName, ref string errorName, string trueCmdLine)
 {
     IntSecurity.UnmanagedCode.Demand();
     if ((outputName == null) || (outputName.Length == 0))
     {
         outputName = tempFiles.AddExtension("out");
     }
     if ((errorName == null) || (errorName.Length == 0))
     {
         errorName = tempFiles.AddExtension("err");
     }
     FileStream stream = CreateInheritedFile(outputName);
     FileStream stream2 = CreateInheritedFile(errorName);
     bool flag = false;
     Microsoft.Win32.SafeNativeMethods.PROCESS_INFORMATION lpProcessInformation = new Microsoft.Win32.SafeNativeMethods.PROCESS_INFORMATION();
     Microsoft.Win32.SafeHandles.SafeProcessHandle processHandle = new Microsoft.Win32.SafeHandles.SafeProcessHandle();
     Microsoft.Win32.SafeHandles.SafeThreadHandle handle2 = new Microsoft.Win32.SafeHandles.SafeThreadHandle();
     SafeUserTokenHandle hNewToken = null;
     try
     {
         Microsoft.Win32.NativeMethods.STARTUPINFO startupinfo;
         StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
         writer.Write(currentDir);
         writer.Write("> ");
         writer.WriteLine((trueCmdLine != null) ? trueCmdLine : cmd);
         writer.WriteLine();
         writer.WriteLine();
         writer.Flush();
         startupinfo = new Microsoft.Win32.NativeMethods.STARTUPINFO {
             cb = Marshal.SizeOf(startupinfo),
             dwFlags = 0x101,
             wShowWindow = 0,
             hStdOutput = stream.SafeFileHandle,
             hStdError = stream2.SafeFileHandle,
             hStdInput = new SafeFileHandle(Microsoft.Win32.UnsafeNativeMethods.GetStdHandle(-10), false)
         };
         StringDictionary sd = new StringDictionary();
         foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
         {
             sd[(string) entry.Key] = (string) entry.Value;
         }
         sd["_ClrRestrictSecAttributes"] = "1";
         byte[] buffer = EnvironmentBlock.ToByteArray(sd, false);
         try
         {
             fixed (byte* numRef = buffer)
             {
                 IntPtr lpEnvironment = new IntPtr((void*) numRef);
                 if ((userToken == null) || userToken.IsInvalid)
                 {
                     RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                         goto Label_0325;
                     }
                     finally
                     {
                         flag = Microsoft.Win32.NativeMethods.CreateProcess(null, new StringBuilder(cmd), null, null, true, 0, lpEnvironment, currentDir, startupinfo, lpProcessInformation);
                         if ((lpProcessInformation.hProcess != IntPtr.Zero) && (lpProcessInformation.hProcess != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE))
                         {
                             processHandle.InitialSetHandle(lpProcessInformation.hProcess);
                         }
                         if ((lpProcessInformation.hThread != IntPtr.Zero) && (lpProcessInformation.hThread != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE))
                         {
                             handle2.InitialSetHandle(lpProcessInformation.hThread);
                         }
                     }
                 }
                 flag = SafeUserTokenHandle.DuplicateTokenEx(userToken, 0xf01ff, null, 2, 1, out hNewToken);
                 if (flag)
                 {
                     RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                     }
                     finally
                     {
                         flag = Microsoft.Win32.NativeMethods.CreateProcessAsUser(hNewToken, null, cmd, null, null, true, 0, new HandleRef(null, lpEnvironment), currentDir, startupinfo, lpProcessInformation);
                         if ((lpProcessInformation.hProcess != IntPtr.Zero) && (lpProcessInformation.hProcess != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE))
                         {
                             processHandle.InitialSetHandle(lpProcessInformation.hProcess);
                         }
                         if ((lpProcessInformation.hThread != IntPtr.Zero) && (lpProcessInformation.hThread != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE))
                         {
                             handle2.InitialSetHandle(lpProcessInformation.hThread);
                         }
                     }
                 }
             }
         }
         finally
         {
             numRef = null;
         }
     }
     finally
     {
         if ((!flag && (hNewToken != null)) && !hNewToken.IsInvalid)
         {
             hNewToken.Close();
             hNewToken = null;
         }
         stream.Close();
         stream2.Close();
     }
 Label_0325:
     if (flag)
     {
         try
         {
             bool flag2;
             ProcessWaitHandle handle4 = null;
             try
             {
                 handle4 = new ProcessWaitHandle(processHandle);
                 flag2 = handle4.WaitOne(0x927c0, false);
             }
             finally
             {
                 if (handle4 != null)
                 {
                     handle4.Close();
                 }
             }
             if (!flag2)
             {
                 throw new ExternalException(SR.GetString("ExecTimeout", new object[] { cmd }), 0x102);
             }
             int exitCode = 0x103;
             if (!Microsoft.Win32.NativeMethods.GetExitCodeProcess(processHandle, out exitCode))
             {
                 throw new ExternalException(SR.GetString("ExecCantGetRetCode", new object[] { cmd }), Marshal.GetLastWin32Error());
             }
             return exitCode;
         }
         finally
         {
             processHandle.Close();
             handle2.Close();
             if ((hNewToken != null) && !hNewToken.IsInvalid)
             {
                 hNewToken.Close();
             }
         }
     }
     int error = Marshal.GetLastWin32Error();
     if (error == 8)
     {
         throw new OutOfMemoryException();
     }
     Win32Exception inner = new Win32Exception(error);
     ExternalException exception2 = new ExternalException(SR.GetString("ExecCantExec", new object[] { cmd }), inner);
     throw exception2;
 }