Exemple #1
0
        private Process StartProcessInternal(ProcessStartInfo startInfo, ExecutionUserContext context, ExecutionPrivileges privileges, int redirectionBufferSize, bool fullProcessAccess)
        {
            if (startInfo.UseShellExecute == true)
            {
                throw new ArgumentException("You cannot use shell execute to execute applications under LUA", "startInfo");
            }
            if (startInfo.UserName.Length > 0)
            {
                throw new ArgumentException("You cannot use user credencials to execute applications under LUA", "startInfo");
            }

            bool runAsUser    = context == ExecutionUserContext.FirstActiveSessionUser;
            bool elevated     = (privileges & ExecutionPrivileges.Administrator) == ExecutionPrivileges.Administrator;
            bool lowIntegrity = (privileges & ExecutionPrivileges.Low) == ExecutionPrivileges.Low;

            //

            //Because the process hosting the proxy has a different Current Directory then
            //this process, we fully qualify the path if it is relative to the current directory.
            string filename = ProcessHelper.GetExeFullPath(startInfo.FileName);

            int    threadId;
            string stdOut, stdErr, stdIn;
            int    pid = proxy.BeginCreateProcess(
                filename,
                startInfo.Arguments,
                startInfo.WorkingDirectory,
                startInfo.CreateNoWindow,
                startInfo.RedirectStandardError,
                startInfo.RedirectStandardInput,
                startInfo.RedirectStandardOutput,
                startInfo.StandardErrorEncoding,
                startInfo.StandardOutputEncoding,
                startInfo.EnvironmentVariables,
                runAsUser,
                null,
                lowIntegrity,
                elevated,
                redirectionBufferSize,
                out threadId,
                out stdOut,
                out stdErr,
                out stdIn);

            //Get the process object
            return(ProcessHelper.EndCreateProcess(startInfo, pid, threadId, stdOut, stdErr, stdIn, redirectionBufferSize, fullProcessAccess));
        }