Is there a way an NON-elevated process can copy a file to a protected directory?

一笑奈何 提交于 2019-12-06 11:52:51

问题


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.


回答1:


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.




回答2:


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", "");




回答3:


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?



来源:https://stackoverflow.com/questions/24634955/is-there-a-way-an-non-elevated-process-can-copy-a-file-to-a-protected-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!