How to write files in c# as an administrator?
I have c#开发者_JAVA技巧 program which writes an xml file to "C:" disk. I published my program as one click package because it's for test purpose only. But the problem is the one click package doesn't have "run as admin" option. So how can I solve this problem ? Any idea ?
The correct solution is not to force administrator elevation to bypass the built-in operating system security.
The correct solution is to fix the broken program. Even though it's just a test program, it should be written correctly.
See this SO question and the answers for more details. Even though it deals with the Program Files
folder instead of the root, the underlying problem and solutions are identical.
I don't know if this works with One Click Deployment, but you could try to include an Manifest with your executable to request that the application is run with higher privileges.
See Create and Embed an Application Manifest (UAC).
精彩评论