c# starting process with lowered privileges from UAC admin level process

流过昼夜 提交于 2019-11-28 01:57:37

You'd better avoid starting a non-elevated process from an elevated one. It's tricky part and error-prone.

This approach is better:

  1. Your updater initially starts as non-elevated application, and its manifest has asInvoker level.
  2. When it starts, it restarts itself with elevated privileges using runas verb, and passes a command-line parameter to indicate it. This instance performs the update and returns.
  3. Here comes the non-elevated updater again, and starts your application with the same non-elevated user token that started the first instance of updater in step 1.

Pretty simple and robust.

Look at this post on how to Enable Drag and Drop for an Elevated process. Even though it says MFC app you can cll those Windows API in Any app I suppose

https://helgeklein.com/blog/2010/03/how-to-enable-drag-and-drop-for-an-elevated-mfc-application-on-vistawindows-7/

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