开发者

C# setup project output automatically start with administrative rights

开发者 https://www.devze.com 2022-12-29 20:06 出处:网络
i\'ve created an setup project for a .net-application which works fine. The problem is, that the application begins to write log-files after startup and this requires administrative rights on windows

i've created an setup project for a .net-application which works fine. The problem is, that the application begins to write log-files after startup and this requires administrative rights on windows vista and windows 7. I know there are some folders which i could use to write into without administrative rights. When i start the application as administrator, everything works fine.

I asked myself, if it's possible to change the setup project in visual studio in a way that the ins开发者_StackOverflow中文版talled application automatically owns administrative rights on the target system?

Thanks for every help in advance!

Alex


You don't want to do this. If it needs rights to a particular directory, then create an account that has them (or modify the subdirectory's rights so that anyone can access it). But don't run as admin just for one feature. Also, look into whether there's another directory you could be writing to, which you already have rights to.


To answer your direct question, yes you can setup a launch condition for the setup project to require administrator, I believe this will take care of the proper escalation for you.

here is a thread with detailed instructions.

Now, to expand, I agree with Steven that you SHOULDN'T do this, at least not just to be able to write a log file.....


You could technically do this with a bad hack: The idea is to have the Setup program which runs elevated create a scheduled task that runs the program as admin.

Instead of directly creating a shortcut to your application, the setup creates an shortcut to execute this scheduled task.

See this as reference on how to do that manually: http://www.howtogeek.com/howto/windows-vista/create-administrator-mode-shortcuts-without-uac-prompts-in-windows-vista/

You just need to find a way to create the task programatically from your setup.

On the other hand, I totally agree with Steven too. Try to do it the 'right' way and don't trick the Windows security. It's a good thing and working around it makes the system potentially unsecure, and you don't want to be the one compromising tht Security of others computers.

0

精彩评论

暂无评论...
验证码 换一张
取 消