简体   繁体   English

你如何在 NSIS 中设置目录权限?

[英]How do you set directory permissions in NSIS?

I'm trying to build a Windows installer using Nullsoft Install System that requires installation by an Administrator.我正在尝试使用需要管理员安装的 Nullsoft 安装系统来构建 Windows 安装程序。 The installer makes a "logs" directory.安装程序创建一个“日志”目录。 Since regular users can run this application, that directory needs to be writable by regular users.由于普通用户可以运行此应用程序,因此该目录需要可由普通用户写入。 How do I specify that all users should have permission to have write access to that directory in the NSIS script language?我如何指定所有用户都应该拥有使用 NSIS 脚本语言对该目录进行写访问的权限?

I admit that this sounds a like a sort of bad idea, but the application is just an internal app used by only a few people on a private network.我承认这听起来有点像坏主意,但该应用程序只是一个内部应用程序,只有少数人在专用网络上使用。 I just need the log files saved so that I can see why the app is broken if something bad happens.我只需要保存日志文件,这样我就可以看到如果发生不好的事情,应用程序为什么会损坏。 The users can't be made administrator.用户不能成为管理员。

Use the AccessControl plugin and then add this to the script, where the "logs" directory is in the install directory.使用AccessControl插件,然后将其添加到脚本中,其中“logs”目录位于安装目录中。

AccessControl::GrantOnFile "$INSTDIR\logs" "(BU)" "FullAccess"

That gives full access to the folder for all users.这为所有用户提供了对该文件夹的完全访问权限。

AccessControl::GrantOnFile "<folder>" "(BU)" "FullAccess" didn't work for me on a Windows Server 2008 machine. AccessControl::GrantOnFile "<folder>" "(BU)" "FullAccess"在 Windows Server 2008 机器上对我不起作用。 Instead I had to use this one:相反,我不得不使用这个:

AccessControl::GrantOnFile "<folder>" "(S-1-5-32-545)" "FullAccess"

S-1-5-32-545 is equivalent to "Users" according to Microsoft Support: Well-known security identifiers in Windows operating systems .根据Microsoft 支持:Windows 操作系统中的众所周知的安全标识符, S-1-5-32-545 相当于“用户”。

Instead of changing the permissions on directories under Program Files, why not put the logs in a location that is writeable by all users.与其更改 Program Files 下目录的权限,不如将日志放在所有用户都可以写入的位置。

See the 4.9.7.7 SetShellVarContext section in your NSIS documentation.请参阅 NSIS 文档中的 4.9.7.7 SetShellVarContext 部分。 You can use it with $APPDATA to get the application data folder that is writeable for all users.您可以将它与 $APPDATA 一起使用来获取对所有用户都可写的应用程序数据文件夹。

It's an old issue now but as suggested by Sören APPDATA directory is a nice way to do what you want, the thing is : Don't take user's personnal APPDATA but the "All Users" APPDATA dir!现在这是一个老问题,但正如 Sören APPDATA 目录所建议的那样,这是一个很好的方式来做你想做的事,事情是:不要拿用户的个人 APPDATA 而是“所有用户”APPDATA 目录! This way anyone will be able to access the log file ;-)这样任何人都可以访问日志文件;-)

Also, I read somewhere that using (BU) on the GrantOnFile is not working well with some systems (Win 7 x64 if I remember well), maybe you should use the SID "(S-1-5-32-545)" instead (it's the All Users' SID, this value is a constant on each Windows OS)另外,我在某处读到在 GrantOnFile 上使用 (BU) 在某些系统上不能正常工作(如果我没记错的话,Win 7 x64),也许您应该使用 SID“(S-1-5-32-545)”代替(它是所有用户的 SID,这个值在每个 Windows 操作系统上都是一个常数)

一种方法:调用外壳,并使用caclsxcacls

Why not create a log-directory in the user's %APPDATA% directory?为什么不在用户的 %APPDATA% 目录中创建一个日志目录? Do you really need to put all the logs in the install directory?你真的需要把所有的日志都放在安装目录中吗? Why?为什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM