public static int Shell(string PathName, AppWinStyle Style = 2, bool Wait = false, int Timeout = -1)
        {
            int num3;

            NativeTypes.STARTUPINFO         lpStartupInfo                  = new NativeTypes.STARTUPINFO();
            NativeTypes.PROCESS_INFORMATION lpProcessInformation           = new NativeTypes.PROCESS_INFORMATION();
            NativeTypes.LateInitSafeHandleZeroOrMinusOneIsInvalid hHandle  = new NativeTypes.LateInitSafeHandleZeroOrMinusOneIsInvalid();
            NativeTypes.LateInitSafeHandleZeroOrMinusOneIsInvalid invalid2 = new NativeTypes.LateInitSafeHandleZeroOrMinusOneIsInvalid();
            int num = 0;

            try
            {
                new UIPermission(UIPermissionWindow.AllWindows).Demand();
            }
            catch (Exception exception)
            {
                throw exception;
            }
            if (PathName == null)
            {
                throw new NullReferenceException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Pathname" }));
            }
            if ((Style < AppWinStyle.Hide) || (Style > ((AppWinStyle)9)))
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Style" }));
            }
            Microsoft.VisualBasic.CompilerServices.NativeMethods.GetStartupInfo(lpStartupInfo);
            try
            {
                int num2;
                lpStartupInfo.dwFlags     = 1;
                lpStartupInfo.wShowWindow = (short)Style;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                }
                finally
                {
                    IntPtr ptr;
                    num2 = Microsoft.VisualBasic.CompilerServices.NativeMethods.CreateProcess(null, PathName, null, null, false, 0x20, ptr, null, lpStartupInfo, lpProcessInformation);
                    if (num2 == 0)
                    {
                        num = Marshal.GetLastWin32Error();
                    }
                    if ((lpProcessInformation.hProcess != IntPtr.Zero) && (lpProcessInformation.hProcess != NativeTypes.INVALID_HANDLE))
                    {
                        hHandle.InitialSetHandle(lpProcessInformation.hProcess);
                    }
                    if ((lpProcessInformation.hThread != IntPtr.Zero) && (lpProcessInformation.hThread != NativeTypes.INVALID_HANDLE))
                    {
                        invalid2.InitialSetHandle(lpProcessInformation.hThread);
                    }
                }
                try
                {
                    if (num2 != 0)
                    {
                        if (Wait)
                        {
                            if (Microsoft.VisualBasic.CompilerServices.NativeMethods.WaitForSingleObject(hHandle, Timeout) == 0)
                            {
                                return(0);
                            }
                            return(lpProcessInformation.dwProcessId);
                        }
                        Microsoft.VisualBasic.CompilerServices.NativeMethods.WaitForInputIdle(hHandle, 0x2710);
                        return(lpProcessInformation.dwProcessId);
                    }
                    if (num == 5)
                    {
                        throw ExceptionUtils.VbMakeException(70);
                    }
                    throw ExceptionUtils.VbMakeException(0x35);
                }
                finally
                {
                    hHandle.Close();
                    invalid2.Close();
                }
            }
            finally
            {
                lpStartupInfo.Dispose();
            }
            return(num3);
        }
Beispiel #2
0
        // Execute a program using the Windows shell.
        public static int Shell
            (String Pathname,
            [Optional][DefaultValue(AppWinStyle.MinimizedFocus)]
            AppWinStyle Style,
            [Optional][DefaultValue(false)] bool Wait,
            [Optional][DefaultValue(-1)] int Timeout)
        {
                        #if CONFIG_EXTENDED_DIAGNOSTICS
            // Split "Pathname" into filename and arguments.
            StringBuilder builder = new StringBuilder();
            if (Pathname == null)
            {
                Pathname = String.Empty;
            }
            int  posn  = 0;
            bool quote = false;
            while (posn < Pathname.Length)
            {
                if (Char.IsWhiteSpace(Pathname[posn]) && !quote)
                {
                    ++posn;
                    break;
                }
                else if (Pathname[posn] == '"')
                {
                    quote = !quote;
                }
                else
                {
                    builder.Append(Pathname[posn]);
                    ++posn;
                }
            }
            String filename = builder.ToString();
            if (filename == null || filename.Length == 0)
            {
                throw new FileNotFoundException
                          (String.Format(S._("VB_CouldntExecute"), "(empty)"));
            }

            // Create the process and start it.
            Process          process = new Process();
            ProcessStartInfo info    = process.StartInfo;
            info.FileName        = filename;
            info.Arguments       = Pathname.Substring(posn);
            info.UseShellExecute = true;
            switch (Style)
            {
            case AppWinStyle.Hide:
                info.WindowStyle = ProcessWindowStyle.Hidden;
                break;

            case AppWinStyle.MinimizedFocus:
            case AppWinStyle.MinimizedNoFocus:
                info.WindowStyle = ProcessWindowStyle.Minimized;
                break;

            case AppWinStyle.MaximizedFocus:
                info.WindowStyle = ProcessWindowStyle.Maximized;
                break;

            case AppWinStyle.NormalFocus:
            case AppWinStyle.NormalNoFocus:
                info.WindowStyle = ProcessWindowStyle.Normal;
                break;

            default:
                throw new ArgumentException
                          (S._("VB_InvalidAppWinStyle"));
            }
            if (!process.Start())
            {
                throw new FileNotFoundException
                          (String.Format(S._("VB_CouldntExecute"), Pathname));
            }
            if (Wait)
            {
                if (process.WaitForExit(Timeout))
                {
                    return(0);
                }
                else
                {
                    return(process.Id);
                }
            }
            else
            {
                return(process.Id);
            }
                        #else
            throw new NotImplementedException();
                        #endif
        }
Beispiel #3
0
 // Methods
 public static int Shell(string PathName, AppWinStyle Style, bool Wait, int Timeout)
 {
 }
	// Methods
	public static int Shell(string PathName, AppWinStyle Style, bool Wait, int Timeout) {}