launching SFC from within a C# app

岁酱吖の 提交于 2019-12-02 03:04:07
Scott Chamberlain

Your console is not elevating, the problem is you can either use the Verb = "runas" and have it elevate or you can use UseShellExecute = false and redirect the outputs, you can not have both.

Your three options are:

  1. Use UseShellExecute = true and disable the redirections
  2. Add a manifest file to your program so it elevates itself as an administrator on start and it can then in turn launch administrative processes and monitor them.
  3. Do a combination of both by writing a 2nd exe that has a manifest file that always runs as administrator. Then have your 1st program launch the 2nd program with Verb = "runas", you then have your 2nd program start SFC with UseShellExecute = false. Your 2nd program then forwards the output via some form of IPC (WCF over named pipes would likely be easiest) to the first unelevated program to be displayed to the user.

Try setting ProcesStartInfo.UserName and ProcessStartInfo.Password to impersonate the new process with elevated credentials.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!