NSIS脚本报错:未正确引入StrFunc StrStr,求解决方法
解决NSIS脚本中StrStr宏的错误问题
问题分析
你遇到的两个错误根源在于StrFunc宏的使用语法错误:
- 第一个错误提示缺少
${Using:StrFunc} StrStr,是因为未正确声明要使用StrStr宏 - 第二个错误
Invalid command: "${UsingStrFunc}"是因为使用了错误的指令名称,正确指令为${Using:StrFunc}而非${UsingStrFunc}
修复步骤
1. 修正StrFunc使用声明
在引入StrFunc.nsh之后,添加正确的宏使用声明:
!include StrFunc.nsh ${Using:StrFunc} StrStr ; 注意冒号和空格的正确格式
2. 确保include顺序正确
所有相关nsh文件必须在宏定义之前引入,正确顺序如下:
!include LogicLib.nsh !include FileFunc.nsh !include StrFunc.nsh ${Using:StrFunc} StrStr ; 必须放在StrFunc.nsh之后、宏定义之前
3. 修正后的完整宏代码
将上述修正应用到你的宏中,完整代码如下:
!include LogicLib.nsh !include FileFunc.nsh !include StrFunc.nsh ${Using:StrFunc} StrStr !macro CHECKPROCESSEXISTANCEMACRO un Function ${un}CheckProcessExistance ;"Check File Running by User" ; Define the process name and the user to check StrCpy $0 "Sky.Suite.Dev11.exe" StrCpy $1 "pck" ; Check if the process is running by the specified user directly nsExec::ExecToStack 'tasklist /FI "IMAGENAME eq $0" /FI "USERNAME eq $1" /FO LIST' Pop $R0 Pop $R1 MessageBox MB_OK|MB_ICONEXCLAMATION "$R1" /SD IDOK ${StrStr} $R3 $R1 "INFO: No tasks are running which match the specified criteria." StrCmp $R3 "" Not_found found found: MessageBox MB_OK|MB_ICONEXCLAMATION "$0 is running by $1. Please close it before starting the installation again." /SD IDOK Abort Not_found: FunctionEnd !macroend
额外说明
StrFunc.nsh中的宏需要显式声明使用,格式为${Using:StrFunc} <宏名称>,支持同时声明多个宏(用空格分隔)- 如果需要使用UnStrStr,只需在声明中添加:
${Using:StrFunc} StrStr UnStrStr
内容的提问来源于stack exchange,提问作者c.k praveen kumar
相关产品推荐
相关产品推荐

