简体   繁体   English

使用NSIS为postgre dbinit执行批处理文件会导致权限被拒绝

[英]Executing batch file for postgre dbinit with NSIS gives permission denied

Following my previous question I'm now trying to execute a batch file trough NSIS code in order to successfully setup the postgres installation after it is being unzipped. 按照我的上一个问题,我现在试图通过NSIS代码执行批处理文件,以便在解压缩postgres安装后成功设置它。 The batch file contains command for initializing the database but it fails because of permission restrictions. 批处理文件包含用于初始化数据库的命令,但由于权限限制而失败。 I am on a Win7 x64 PC. 我在Win7 x64 PC上。 My user account is the administrator and I start the Setup.exe with Run as adminitrator option. 我的用户帐户是管理员,我使用Run as adminitrator选项启动Setup.exe。 This is the error I get: 这是我得到的错误:

C:\\Program Files (x86)\\Poker Assistant>cd "pgsql\\bin" C:\\Program Files (x86)\\Poker Assistant\\pgsql\\bin>initdb -U postgres -A password --pwfile "pwd.txt" -E utf8 -D "..\\data" The files belonging to this database system will be owned by user "Mandarinite". C:\\ Program Files(x86)\\ Poker Assistant> cd“ pgsql \\ bin” C:\\ Program Files(x86)\\ Poker Assistant \\ pgsql \\ bin> initdb -U postgres-密码--pwfile“ pwd.txt”- E utf8 -D“ .. \\ data”属于此数据库系统的文件将由用户“ Mandarinite”拥有。

This user must also own the server process. 该用户还必须拥有服务器进程。

The database cluster will be initialized with locale "Bulgarian_Bulgaria.1251". 数据库集群将使用语言环境“ Bulgarian_Bulgaria.1251”进行初始化。 initdb: could not find suitable text search configuration for locale "Bulgarian_ Bulgaria.1251" The default text search configuration will be set to "simple". initdb:找不到适合语言环境“ Bulgarian_ Bulgaria.1251”的文本搜索配置。默认的文本搜索配置将设置为“简单”。

Data page checksums are disabled. 数据页校验和已禁用。

creating directory ../data ... initdb: could not create directory "../data": Permission denied 正在创建目录../data ... initdb:无法创建目录“ ../data”:权限被拒绝

EDIT: After tinkering little more with the installer I got to the root of the problem. 编辑:在对安装程序进行了更多修改之后,我找到了问题的根源。 I cannot in any way execute the following command when the installation is in the Program Files folder: 当安装位于Program Files文件夹中时,我无法以任何方式执行以下命令:

initdb -U postgres -A password --pwfile "pwd.txt" -E utf8 -D "..\data"

I tried from .bat file. 我尝试从.bat文件。 I tried from .cmd file. 我尝试从.cmd文件。 I tried manually from Command Prompt. 我从命令提示符手动尝试。 I tried start as Administrator. 我尝试以管理员身份开始。 All attempts resulted in the Permission denied error 所有尝试均导致Permission denied错误

EDIT2: I did not find any way to fix the problem so I made a workaround. EDIT2:我没有找到解决此问题的任何方法,所以我采取了一种解决方法。 Now I distribute the postgres with its data directory already initialized. 现在,我发布的postgres及其数据目录已经初始化。 Then I only need to create the service and start it. 然后,我只需要创建服务并启动它。

I just realised what the issue here is. 我刚刚意识到这里的问题是什么。

If you run postgres as Administrator, it uses a special Windows API call to drop permissions (acquire a restricted token), so that it runs without full Administrator rights for security. 如果您以管理员身份运行postgres ,它将使用特殊的Windows API调用来删除权限 (获取受限制的令牌),因此它在运行时将没有完整的管理员权限来确保安全。 See PostgreSQL utilities and restricted tokens on windows . 请参阅Windows上的PostgreSQL实用程序和受限令牌

I suspect that what's happening here is that initdb isn't creating the target data directory and setting its permissions before doing that, so it drops permissions and then doesn't have the permissions to create the data directory. 我怀疑这里发生的事情是initdb并未创建目标数据目录并之前设置其权限,因此它放弃了权限,然后没有创建数据目录的权限。

To work around it, simply md ..\\data to create the empty directory and then use icacls.exe to grant appropriate permissions before you try to initdb . 要解决此问题,只需在尝试启动initdb之前,使用md ..\\data创建一个空目录,然后使用icacls.exe授予适当的权限。 Or, even better, store it in a more appropriate place like %PROGRAMDATA%\\MyApp\\pgdata or whatever; 或者,甚至更好地将其存储在%PROGRAMDATA%\\MyApp\\pgdata等更合适的位置; application data should not go in %PROGRAMFILES% . 应用程序数据应该走%PROGRAMFILES%

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

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