Home >Backend Development >C++ >How Can I Programmatically Elevate Process Privileges in C# to Run InstallUtil.exe?
You encounter problems when you use to install the service. Code fragment provided:
It runs successfully under the promotion command prompt, but fails when calling in your application.
Process.Start
Solution: Promotion of permissions InstallUtil.exe
<code class="language-csharp">ProcessStartInfo startInfo = new ProcessStartInfo(m_strInstallUtil, strExePath); System.Diagnostics.Process.Start(startInfo);</code>This problem comes from insufficient process authority. To grant you the permissions to improve your process, you can set the
attribute of the
object to "runas":This command indicates that Windows executes the process with the administrator's permissions to simulate the effect of calling its effect through the "Run as an administrator" option in the resource manager.
UAC Precautions startInfo
Verb
<code class="language-csharp">startInfo.UseShellExecute = true; startInfo.Verb = "runas";</code>
alternative: embedded the list
To avoid UAC prompts, consider increasing the authority by embedding the list. This will display a UAC prompt at the time of the application and automatically increase the permissions of all its sub -processes, thereby no additional prompts.
The above is the detailed content of How Can I Programmatically Elevate Process Privileges in C# to Run InstallUtil.exe?. For more information, please follow other related articles on the PHP Chinese website!