Inno Setup 安装 - 访问被拒绝
我已经使用 inno setup 创建了一个安装。我的应用程序(除其他外)运行后会在子文件夹中创建一个 pdf 文件,然后打开它。但 Windows 7 说访问被拒绝并弹出异常。怎么了?如何使用 innosetup 授予对子文件夹的访问权限? 这是 ino 中的代码片段:
Source: "C:\Users\Someone\Desktop\NET\Animations\*"; DestDir: "{app}\Animations"; Flags: ignoreversion recursesubdirs createallsubdirs
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是因为您尝试从不同用户的私人文件夹复制文件。那是禁区。您只能将文件放入当前用户的文件夹(正在运行安装的文件夹)。无论如何,很难想象有什么充分的理由让你想要这样做。
尝试改用
{userdocs}
常量。使用ExpandConstant
将其扩展为完整路径。如果您需要将某些内容放在所有用户都可以访问的位置,则需要以管理权限运行安装程序。然后,您将能够从
所有用户
配置文件目录中读取/写入。编辑:啊,抱歉。我完全错过了您问题中您所说的安装后尝试执行此操作的部分。我只是查看了代码,并认为这是您在设置过程中让 Inno Setup 执行的操作。
对于安装完成后的某些事情,这是完全不同的答案。 Windows 7(感谢 UAC)不允许您的应用(或任何< /em> app,就此而言)写入系统文件夹。其中包括
Windows
目录、Program Files
文件夹及其包含的任何文件夹。这是一项安全措施,旨在阻止应用程序在不属于它们的地方疯狂运行。您有几个不同的选择:
如果您绝对需要对
Program Files
文件夹的写入权限,您可以提示用户提升应用程序的进程。基本上,这意味着您将请求管理权限,并且他们会看到 UAC 中的一个框,要求他们输入密码。我在 我对这个问题的回答。对于用任何其他语言编写的应用程序,您将遵循类似的步骤;您只是调用 Windows API 中内置的函数。
不过,更好的选择是修改您的应用程序,使其不必写入系统文件夹。这样,您就不必以管理权限运行。这是所有标准 Windows 应用程序的预期模型。 Microsoft 至少从 Windows 2000 早期就开始推荐它,但直到 Vista 才真正强制您遵循它。
我在 我对这个问题的回答。
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. UseExpandConstant
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 theProgram 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:
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.
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.