0

I have a VDProj project which I use to create a setup program for my application. I've had to install Visual Studio 2010 (on another machine) to allow me to run this, as it has been removed from VS2012.. very annoying.. but that's a different thread.

When the end user installs the program, it creates the files in the c:\program files\mycompany\ folder, which inherits the security from the parent directory, which has no write access for the user.

The problem is, that when my program runs, it creates some log files, and also does a software update if required. So my application requires write access to the directory.

I'm guessing that I could install the software into the 'MyDocuments' folder, or another folder which has write access, but was wondering if there's a better way of doing this?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Rich S
  • 3,248
  • 3
  • 28
  • 49
  • This is entirely normal, a Windows feature called UAC. Surely you've heard of it. Use the AppData folder to write files, use Environment.GetFolderPath() – Hans Passant Aug 01 '13 at 00:46
  • If this was just storing log files, or other things, that would be fine, but I'm also doing an automatic update to the software, which requires me to write to the program directory. – Rich S Aug 01 '13 at 09:15

1 Answers1

0

When your program needs to write to protected locations like Program Files, you can launch it using ShellExecute functionality and the runas verb/operation. That will trigger a consent dialog from UAC to require an administrator to give permission for the elevation. That would be annoying if it happens too often, so only do it when necessary.

Bob Arnson
  • 21,377
  • 2
  • 40
  • 47