Home  >  Article  >  Backend Development  >  Can C Applications Request Administrator Privileges at Runtime?

Can C Applications Request Administrator Privileges at Runtime?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-13 02:05:02866browse

Can C   Applications Request Administrator Privileges at Runtime?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn