更改NSIS中的默认安装文件夹(Change the default install folder in NSIS)

编程入门 行业动态 更新时间:2024-10-28 12:30:33
更改NSIS中的默认安装文件夹(Change the default install folder in NSIS)

我正在使用nsis编写windows安装程序。 此安装程序包含一个运行在xampp上的Web应用程序,因此xampp也作为此应用程序的服务安装。 但是xamp在Windows 7的64位计算机上安装时会出现问题。这是由于C:\ Program Files(x86)中的目录路径问题,如此处所述。

XAMPP错误解决方案? 我已经安装在我的Windows XP Dual Boot Machine上

但是目前安装程序中的自动安装路径设置如下。

C:\Program Files (x86)\myapplication

安装程序脚本只有以下宏来添加目录选择器页面。

!insertmacro MUI_PAGE_DIRECTORY

作为一种解决方案,我要做的是采取以下行动。

将默认目录更改为c:\ Program Files 如果用户选择x86文件夹,请提供错误消息以选择另一个目录。

为此,我需要获取安装目录路径

$INSTDIR

检查是否存在具有该路径的x86子字符串 如果是的话给出错误信息。 将默认路径更改为c:\ Program Files

由于我对nsis不太了解,所以无法编写这个程序。

有人可以帮我解决这个问题吗?

I'm writing a installer for windows using nsis. This installer contains a web application which is run on top of xampp, so xampp is also installed as a service with this application. But xamp gives an issue when it installed in 64bit machine on Windows 7. This is due to the directory path issue in C:\Program Files (x86) as mentioned here.

XAMPP Error Solution? I have that installed on my Windows XP Dual Boot Machine

But currently the automatic installation path is set as follows in the installer.

C:\Program Files (x86)\myapplication

The installer script just have the following macro to add the directory chooser page.

!insertmacro MUI_PAGE_DIRECTORY

As a solution what I'm going to do are following actions.

Change the default directory to c:\Program Files If the user choose the x86 folder give an error message to choose another directory.

For that I need to get the install directory path by

$INSTDIR

and

check whether there is a sub string of x86 with that path if so give the error messages. Change the default path to c:\Program Files

Since I'm not much familiar with nsis I'm unable to write this program.

Can someone help me on this issue?

最满意答案

在win7 / 64上,可以通过%ProgramW6432%环境变量从32位应用程序获取64位程序文件。

你可以试着用ReadEnvStr来获得它:

在32位系统上它将返回一个空字符串 在64位系统上它将返回c:\program files (如果没有在别处配置)

这是测试它的一个片段:

ReadEnvStr $0 ProgramW6432 StrCmp $0 "" 0 +3 MessageBox MB_OK "it is a 32b system" goto +2 MessageBox MB_OK "it is a 64b system"

在你的情况下,它可以这样做:

ReadEnvStr $0 ProgramW6432 StrCmp $0 "" +2 0 StrCpy $INSTDIR $0

编辑 :为了拒绝Program Files (x86)您可以使用Anders给出的另一个问题的.onVerifyInstDir回调方法,它将检查选择的目录,因为它是由用户选择的,并且在更改页面之前:

Function .onVerifyInstDir ReadEnvStr $0 "ProgramFiles(x86)" StrCmp $0 $INSTDIR 0 PathGood MessageBox MB_OK "directory not valid for installation" Abort PathGood: FunctionEnd

在这里,我使用另一个环境变量来获取程序文件的(x86)变体。

On a win7/64, the 64 bits program files can be get from a 32 bit application via the %ProgramW6432% environment variable.

You could try to get it with ReadEnvStr :

on a 32bit system it will return an empty string on a 64 bit system it will return c:\program files (if not configured elsewhere)

Here is a snippet that test it :

ReadEnvStr $0 ProgramW6432 StrCmp $0 "" 0 +3 MessageBox MB_OK "it is a 32b system" goto +2 MessageBox MB_OK "it is a 64b system"

In your case, it could do :

ReadEnvStr $0 ProgramW6432 StrCmp $0 "" +2 0 StrCpy $INSTDIR $0

Edit: For the point to refuse Program Files (x86) you could use the .onVerifyInstDir callback method that was given by Anders for another question, it will check the choosen directory as it is selected by the user and before changing the page :

Function .onVerifyInstDir ReadEnvStr $0 "ProgramFiles(x86)" StrCmp $0 $INSTDIR 0 PathGood MessageBox MB_OK "directory not valid for installation" Abort PathGood: FunctionEnd

Here, I use another environment variable to get the (x86) variant of program files.

更多推荐

本文发布于:2023-07-22 06:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1217739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   Change   NSIS   folder   install

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!