2

I have created an installation with inno setup. My app (among other things) after is run creates a pdf file inside a subfolder and then opens it. But windows 7 says access denied and exception pops up. What's wrong? How to grant access to subfolders using innosetup? Here's the code snippet inside ino:

Source: "C:\Users\Someone\Desktop\NET\Animations\*"; DestDir: "{app}\Animations"; Flags: ignoreversion recursesubdirs createallsubdirs
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

4

Presumably because you're trying to copy the file from a different user's private folder. That's off-limits. You can only place files into the current user's folder (the one who is running the install). It's difficult to imagine a good reason why you'd want to do otherwise, anyway.

Try using the {userdocs} constant, instead. Use ExpandConstant to expand it to the full path.

If you need things to go in a location that will be accessible to all users, you need to run the installer with Administrative privileges. Then, you'll be able to read/write from the All Users profile directory.


EDIT: Ah, sorry. I totally missed the part of your question where you said you were trying to do this after installation. I just looked at the code and thought this was something you were having Inno Setup do during the setup process.

It's a completely different answer for something after the installation has completed. Windows 7 (thanks to UAC) doesn't let your app (or any app, for that matter) write to system folders. That includes the Windows directory, as well as the Program Files folder and any of the folders it contains. This is a security measure, intended to stop applications from running amok in places where they don't belong.

You have a couple of different options:

  1. If you absolutely need write access to the Program Files folder, you can prompt the user to elevate your application's process. Basically, that means that you'll be requesting Administrative privileges, and they'll see a box from UAC asking them for a password.

    I give more information about how you might go about doing that from a C# application in my answer to this question. You'll follow similar steps for an app written in any other language; you're just calling functions built into the Windows API.

  2. The better option, though, is to modify your application so that it doesn't have to write to system folders. That way, you won't have to run with Administrative privileges. This is the intended model for all standard Windows applications. Microsoft has been recommending it at least since the early days of Windows 2000, but you weren't actually forced into following it until Vista.

    I talk more about the various places that an app has write access to (and the various uses of each) in my answer to this question.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • It's like this: On my desktop I have a folder and subfolders, when I incorporate that into ino setup and after installation in Program Files (X86) I have the same structure but my app can not write to these folders after installation. Says Access denied. What's wrong? –  Apr 06 '11 at 15:21
  • @Rawn: Sorry, I apparently misread your question. I've updated my answer; see if that helps. – Cody Gray - on strike Apr 06 '11 at 15:30
  • Thank you for your answer. I found that the solution is putting the following into setup file: [Dirs] Name: "{app}\Animations"; Permissions: everyone-modify; –  Apr 06 '11 at 18:30
  • @Rawn: Yes, you can change the permissions, but it's the wrong approach. Your installer runs as an elevated process (any app named `setup.exe` will; it's a special case for compatibility reasons), so it has the ability to set permissions on any folder that it wants. You could also grant everyone access to the `Windows` folder, but it's *definitely* a bad idea. It's not clear why you resist simply following best practices and storing your app's data in the `AppData` folder. – Cody Gray - on strike Apr 07 '11 at 06:47
  • I have a main app that launches 100 of small exe demos in their respective subfolders. Some of those exes require for example a database like access accdb to be in the same folder. That would pose a problem for me. –  Apr 07 '11 at 14:00