Run CFile::Open as admin
-
Is there possible to run
CFile::Open
in order to write a text file, inside C:\Program Files\ location, with administrator rights, even the application who call this are not started with administrator rights ?There is no way. A running process can not get higher privileges. All you can do is starting another process using
ShellExecuteEx
with the "runas" verb which usually shows the UAC prompt. Another option is running your application with sufficient priviliges and drop those when no longer needed. See permissions - Dropping privileges in C++ on Windows - Stack Overflow[^]. See also the CP article Riding the Vista UAC elevator, up and down[^]. But I suggest to rethink your request. An application should not modify data in the Program Files directory tree. That should be only modified by installation and update processes. Windows provides common directories for application specific data (shared and per user). -
There is no way. A running process can not get higher privileges. All you can do is starting another process using
ShellExecuteEx
with the "runas" verb which usually shows the UAC prompt. Another option is running your application with sufficient priviliges and drop those when no longer needed. See permissions - Dropping privileges in C++ on Windows - Stack Overflow[^]. See also the CP article Riding the Vista UAC elevator, up and down[^]. But I suggest to rethink your request. An application should not modify data in the Program Files directory tree. That should be only modified by installation and update processes. Windows provides common directories for application specific data (shared and per user).