Run-Time Administrator Privilege Request in C
Is it feasible to enable a Windows-based C application to request administrator privileges dynamically? Elevated privileges are attainable during compilation, but can they be granted at run time as well?
Run-Time Elevation
If you desire the application to perpetually run with elevated privileges, you can supply it with a manifest, which can be embedded during compilation or placed as an external file alongside the executable. However, if you wish to manually select elevated execution, you can right-click the executable or shortcut and choose "Run As Administrator."
Programmatic Elevation
To elevate privileges programmatically, utilize the "runas" verb while launching a process:
ShellExecute( NULL, "runas", "c:\windows\notepad.exe", " c:\temp\report.txt", NULL, // default dir SW_SHOWNORMAL );
This allows you to elevate privileges for specific actions or processes without compromising the overall application's integrity.
The above is the detailed content of Can C Applications Request Administrator Privileges at Runtime?. For more information, please follow other related articles on the PHP Chinese website!