0

I need to do some registry operations & other system operations for that i need admin permission. currently user have to start my application as "Run as administrator".

so How could i launch my application with admin rights?

mahipat
  • 28
  • 1
  • 5

4 Answers4

2

CreateProcessAsUser or CreateProcessWithLogonW is the main thing you need. For CreateProcessAsUser, you'll need to use a few other things to make it do its tricks though (e.g., AdjustTokenPrivileges to enable the privileges it uses, and LogonUser to get a user's token).

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
2

You can also use ShellExecuteEx() for this purpose. This routine expects a SHELLEXECUTEINFO structure to be passed to it. The relevant attribute of this structure is "lpverb" which has to be set to a value "runas". This will ensure that the task that is run with elevated priveleges.

Raj
  • 114
  • 3
1

The answers deal with starting it programatically, but if the program's entire purpose is to run as admin to make these changes, you can add an appropriate manifest to make Windows elevate for you.

Community
  • 1
  • 1
Deanna
  • 23,876
  • 7
  • 71
  • 156
0

If just part of your application needs admin access, look at COM elevation.

Deanna
  • 23,876
  • 7
  • 71
  • 156