当前位置: 首页>>代码示例>>C#>>正文


C# STARTUPINFO.GetType方法代码示例

本文整理汇总了C#中STARTUPINFO.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# STARTUPINFO.GetType方法的具体用法?C# STARTUPINFO.GetType怎么用?C# STARTUPINFO.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在STARTUPINFO的用法示例。


在下文中一共展示了STARTUPINFO.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunProcess

        public Process RunProcess(ProcessPrisonRunInfo runInfo)
        {
            if (!this.Created)
            {
                throw new InvalidOperationException("ProcessPrison has to be created first.");
            }

            var startupInfo = new STARTUPINFO();
            var processInfo = new PROCESS_INFORMATION();

            startupInfo.cb = Marshal.SizeOf(startupInfo.GetType());
            // startupInfo.dwFlags = 0x00000100;

            string env = BuildEnvironmentVariable(runInfo.EnvironmentVariables);

            var creationFlags = ProcessCreationFlags.ZERO_FLAG;

            creationFlags &=
                ~ProcessCreationFlags.CREATE_PRESERVE_CODE_AUTHZ_LEVEL;

            creationFlags |=
                ProcessCreationFlags.CREATE_SEPARATE_WOW_VDM |

                ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE |
                ProcessCreationFlags.CREATE_NEW_PROCESS_GROUP |
                ProcessCreationFlags.CREATE_NO_WINDOW |
                ProcessCreationFlags.CREATE_SUSPENDED |
                ProcessCreationFlags.CREATE_UNICODE_ENVIRONMENT;

            if (runInfo.Interactive)
            {
                creationFlags |= ProcessCreationFlags.CREATE_NEW_CONSOLE;
                // startupInfo.lpDesktop = @"winsta0\default"; // set additional ACLs for the user to have access to winsta0/default
            }
            else
            {
                creationFlags |= ProcessCreationFlags.CREATE_NO_WINDOW;
                // http://support.microsoft.com/kb/165194
                // startupInfo.lpDesktop = this.Id + "\\" + "default";
                // TODO: isolate the Windows Station and Destop
            }

            if (string.IsNullOrEmpty(this.WindowsUsername))
            {
                throw new InvalidOperationException("This should not be run without a user");
            }
            else
            {

                SECURITY_ATTRIBUTES secAttributes = new SECURITY_ATTRIBUTES();
                secAttributes.nLength = Marshal.SizeOf(secAttributes);

                IntPtr windowStation = CreateWindowStation(this.WindowsUsername, 0, WINDOWS_STATION_ACCESS_MASK.WINSTA_NONE, null);
                IntPtr desktop = IntPtr.Zero;

                lock (windowStationLock)
                {
                    IntPtr currentWindowStation = GetProcessWindowStation();

                    try
                    {
                        bool setOk = SetProcessWindowStation(windowStation);

                        if (!setOk)
                        {
                            throw new Win32Exception(Marshal.GetLastWin32Error());
                        }

                        CreateDesktop(this.WindowsUsername, null, null, 0, ACCESS_MASK.DESKTOP_CREATEWINDOW, null);

                        startupInfo.lpDesktop = string.Format(@"{0}\{0}", this.WindowsUsername);

                        byte[] envBlock = CreateEnvironment(myenvvars);

                        // Create the process in suspended mode to fence it with a Windows Job Object
                        // before it executes.
                        // TODO: Use CreateProcessWithToken to prevent Windows for creating an unamed job object for the
                        // second created process.
                        // http://stackoverflow.com/questions/1287620/createprocesswithlogonw-and-assignprocesstojobobject
                        bool ret = CreateProcessWithLogon(
                            this.WindowsUsername,
                            this.WindowsDomain,
                            this.WindowsPassword,
                            LogonFlags.LOGON_NETCREDENTIALS_ONLY,
                            runInfo.FileName,
                            runInfo.Arguments,
                            creationFlags,
                            UnicodeEncoding.Unicode.GetString(envBlock),
                            runInfo.WorkingDirectory,
                            ref startupInfo,
                            out processInfo
                            );

                        if (!ret)
                        {
                            throw new Win32Exception(Marshal.GetLastWin32Error());
                        }
                    }
                    finally
                    {
//.........这里部分代码省略.........
开发者ID:UhuruSoftware,项目名称:vcap-dotnet,代码行数:101,代码来源:ProcessPrison.cs


注:本文中的STARTUPINFO.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。