C#将当前运行进程提升为SYSTEM

时间:2017-04-02 07:21:03

标签: c# process system elevated-privileges

如何将当前运行过程提升为系统,而不是管理员。

try
        {
            var ps = new ProcessStartInfo();
            ps.FileName = Process.GetCurrentProcess().ProcessName.ToString() + ".exe";
            ps.Verb = "runas";
            this.Close();

            var process = new Process();
            process.StartInfo = ps;
            process.Start();
        }
        catch (Exception re)
        {
            this.TopMost = true;
            MessageBox.Show(re.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
        finally
        {
            Application.Exit();
        }

上面的代码将当前正在运行的程序重新启动到管理员权限,就像我明智的如何获得SYSTEM权限一样?

c#4.5

有机会创建一个新的进程作为SYSTEM吗?因为我看到一些应用程序(RunAsSystem)可以使文件作为SYSTEM进程启动。

感谢。

1 个答案:

答案 0 :(得分:0)

无法以系统方式启动流程。这只能在启动时/内核级方案,驱动程序,服务等方面实现。 如果可以做到这将是一个安全风险。如果您将逻辑作为系统运行,则创建Windows服务。