Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Run CFile::Open as admin

Run CFile::Open as admin

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    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 ?

    J 1 Reply Last reply
    0
    • _ _Flaviu

      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 ?

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      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).

      _ 1 Reply Last reply
      0
      • J Jochen Arndt

        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).

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Ok, understood. Thank you.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups