views:

864

answers:

4

Hi,

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 installed application automatically owns administrative rights on the target system?

Thanks for every help in advance!

Alex

+4  A: 

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.

Steven Sudit
For the record, this was downvoted arbitrarily by someone who is unhappy with me.
Steven Sudit
A: 

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

Mitchel Sellers
That's an interesting answer, but I'm not sure if it matches the question. If I understand correctly, Alex would like the application to have rights to a log directory when it executes, while the link you posted is about ensuring that the setup program is run as admin. Now, in principle, the setup could take advantage of being admin by modifying the DACL of the log directory to expose it to all users, but while this might work, I would not recommend it.
Steven Sudit
@Steven - I would agree, but this does get the poster the question what they want, with the application running as administrator, they can do what they need to do. I agree though that a different alternative should be done. Escalating for logging purposes, is not a "good" solution
Mitchel Sellers
I think we're on the same page here.
Steven Sudit
A: 

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.

Sebastian P.R. Gingter
A: 

Thanks for the answers and hints!

Maybe I didn't describe my problem exactly. I don't need to check the user for admin rights for the installation procedure, I need the rights when I perform the application because the application writes a log file into the applications folder which needs admin rights (at least in Windows Vista and 7).

Of course it's not a good idea to trick the windows security. I just wanted to ask if it's possible in a proper way. As Steven Sudit wrote, the best way to write files during runtime is to use the folders which the current user has the rights to write into.

The suggestion above from Sebastian P. R. Ginter would work but as he said, it's a "bad hack" and it would compromise the security of the system. So I leave my hands off this solution ;-)

Many thanks once again!

Alex

Alex
One other possibility is to create a subfolder as part of installation and change its DACL to allow Everyone access to it. The app still runs under a normal account, and you only expose the log subdirectory, not the directory that has the code.
Steven Sudit
How exactly can I do that? I created a folder in my setup project (file system view -> application folder -> add folder). How can i now change the DACL? Couldn't find it. Or do i have to change that programmatically? Thank you very much!
Alex
@Alex: Programmatically.
Steven Sudit