C # startup process with reduced privileges from the UAC administration level process

I have one serious problem with my application. I have an application and update as separate exe files. When an update is available, the update program updates, and when the process completes, it launches my application. The main problem is that the application is installed in the program files folder, therefore, UAC administrator privileges are required for updating, and this is normal, but when I need to run the application to update applications, it should start as a regular user, because if it starts as admin, drag and drop does not work (no application problem, UAC blocks it). I tried several different solutions, and even this one: How to run NOT elevated in Vista (.NET)

This did not help me - my application starts as an administrator.

+6
source share
2 answers

It is better to avoid starting a failed process from an elevated level. This is the hard part and error prone.

This approach is better:

  • Your update first starts as a non- asInvoker application, and its manifest is at asInvoker level.
  • At startup, it restarts itself with elevated privileges using runas verb and passes a command-line option to specify it. This instance performs the update and returns.
  • Here, the unrecoverable update module is added again and your application starts with the same unprofitable token of the user who launched the first update instance in step 1.

Pretty simple and reliable.

+9
source

Have a look at this post on how to enable drag and drop for an elevated process. Despite what he says about the MFC application, you can use these Windows APIs in any application. I suppose,

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

0
source

Source: https://habr.com/ru/post/899930/


All Articles