示例#1
0
        private TMProcess InnerCreateProcessAsUser()
        {
            this.InnerElevateProcess(PrivilegeConstants.SeAssignPrimaryTokenPrivilege, PrivilegeConstants.SeIncreaseQuotaPrivilege);

            STARTUPINFO         si = new STARTUPINFO();
            PROCESS_INFORMATION pi;
            SECURITY_ATTRIBUTES saProcessAttributes = new SECURITY_ATTRIBUTES();
            SECURITY_ATTRIBUTES saThreadAttributes  = new SECURITY_ATTRIBUTES();

            if (!Advapi32.CreateProcessAsUser(this.TokenHandle.GetHandle(), this.Application, this.CommandLine, ref saProcessAttributes,
                                              ref saThreadAttributes, false, 0, IntPtr.Zero, null, ref si, out pi))
            {
                Logger.GetInstance().Error($"Failed to create shell. CreateProcessAsUser failed with error code: {Kernel32.GetLastError()}");
                throw new Exception();
            }

            return(TMProcess.GetProcessById(pi.dwProcessId));
        }
示例#2
0
        private TMProcess InnerCreateProcessWithToken()
        {
            this.InnerElevateProcess(PrivilegeConstants.SeImpersonatePrivilege);

            STARTUPINFO si = new STARTUPINFO();

            if (this.Interactive)
            {
                si = this.InnerSetupInteractive();
            }

            PROCESS_INFORMATION pi;

            if (!Advapi32.CreateProcessWithTokenW(this.TokenHandle.GetHandle(), LogonFlags.NetCredentialsOnly,
                                                  this.Application, this.CommandLine, CreationFlags.NewConsole, IntPtr.Zero, @"C:\", ref si, out pi))
            {
                Logger.GetInstance().Error($"Failed to create shell. CreateProcessWithTokenW failed with error code: {Kernel32.GetLastError()}");
                throw new Exception();
            }

            return(TMProcess.GetProcessById(pi.dwProcessId));
        }