Home > Backend Development > C++ > body text

Can C Applications Request Administrator Privileges at Runtime?

Mary-Kate Olsen
Release: 2024-11-13 02:05:02
Original
901 people have browsed it

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  
); 
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template