简体   繁体   English

更改NSIS中的默认安装文件夹

[英]Change the default install folder in NSIS

I'm writing a installer for windows using nsis. 我正在使用nsis编写Windows安装程序。 This installer contains a web application which is run on top of xampp, so xampp is also installed as a service with this application. 此安装程序包含一个在xampp之上运行的Web应用程序,因此xampp也作为此应用程序的服务安装。 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. 但是xamp在Windows 7上安装在64位机器上会出现问题。这是由于此处提到的C:\\ Program Files(x86)中的目录路径问题。

XAMPP Error Solution? XAMPP错误解决方案? I have that installed on my Windows XP Dual Boot Machine 我已经在我的Windows XP双引导机上安装了它

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. 作为一种解决方案,我要做的就是采取行动。

  1. Change the default directory to c:\\Program Files 将默认目录更改为c:\\ Program Files
  2. If the user choose the x86 folder give an error message to choose another directory. 如果用户选择x86文件夹,则会给出错误消息以选择另一个目录。

For that I need to get the install directory path by 为此,我需要获取安装目录路径

$INSTDIR

and

  1. check whether there is a sub string of x86 with that path 检查是否存在具有该路径的x86子字符串
  2. if so give the error messages. 如果是这样给出错误消息。
  3. Change the default path to c:\\Program Files 将默认路径更改为c:\\ Program Files

Since I'm not much familiar with nsis I'm unable to write this program. 由于我对nsis不太熟悉,我无法编写这个程序。

Can someone help me on this issue? 有人可以帮我解决这个问题吗?

NSIS提供$ PROGRAMFILES32和$ PROGRAMFILES64:

InstallDir "$PROGRAMFILES64\myapp"

On a win7/64, the 64 bits program files can be get from a 32 bit application via the %ProgramW6432% environment variable. 在win7 / 64上,可以通过%ProgramW6432%环境变量从32位应用程序获取64位程序文件。

You could try to get it with ReadEnvStr : 您可以尝试使用ReadEnvStr获取它:

  • on a 32bit system it will return an empty string 在32位系统上,它将返回一个空字符串
  • on a 64 bit system it will return c:\\program files (if not configured elsewhere) 在64位系统上,它将返回c:\\program files (如果未在其他地方配置)

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 : 编辑 :对于拒绝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

Here, I use another environment variable to get the (x86) variant of program files. 在这里,我使用另一个环境变量来获取程序文件的(x86)变体。

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

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