Reputation: 5111
I am fine with it asking the user for elevation when it is ready to copy a file. The program that needs to do the copying cannot run elevated (it looses many important environment variables and I am not in a position to change the way it is started). My fallback will be to have it spawn a process with elevation that actually does the file copy, but I would prefer not to have to add yet another exe to what I am working on.
Upvotes: 2
Views: 292
Reputation: 595320
Use the COM Elevation Moniker to instantiate the IFileOperation
shell interface, then all file operations done with that interface will be elevated without having to elevate the calling process, or having to create a separate EXE/process to handle the file access.
Upvotes: 5
Reputation: 256581
You need to ShellExecute
a copy of your program using the runas
verb. That will cause the copy to be elevated. This elevated process can then do the thing.
Typically you pass a copy of yourself a command line option indicating you want to do that protected thing:
ShellExecute(0, "runas" "Frobber.exe", "-doThatThingThatRequiresElevation", "");
Upvotes: 0
Reputation: 5111
The accepted wisdom is that this is not possible because you cannot elevate a program as it is running. Also see: Can a process elevate itself after startup?
Upvotes: -1