转自 http://hi.csdn.net/jinglidong

!include "LogicLib.nsh"
使用 NSIS 的宏来提供各种逻辑基本语句,不需要预先添加函数。
  • 基本语句

If|Unless..{ElseIf|ElseUnless}..[Else]..EndIf|EndUnless
- 有条件的执行一个语句区块,取决于表达式。

AndIf|AndUnless|OrIf|OrUnless
- 给 If、Unless、ElseIf 和 ElseUnless 增加额外的条件语句。

IfThen..|..|
- 有条件的执行一个内联语句,取决于表达式。

IfCmd..||..|
- 条件的执行一个内联语句,取决于 NSIS 函数提供的真值。

Select..{Case[2|3|4|5]}..[CaseElse|Default]..EndSelect
- 执行多个语句区块之一,取决于表达式的值。

Switch..{Case|CaseElse|Default}..EndSwitch
- 跳转到多个标记之一,取决于表达式的值。

Do[While|Until]..{ExitDo|Continue|Break}..Loop[While|Until]
- 重复一个语句区块直到停止 取决于表达式的值。

While..{ExitWhile|Continue|Break}..EndWhile
- DoWhile..Loop的别名(向后兼容)

For[Each]..{ExitFor|Continue|Break}..Next
- 重复语句区块来连续改变变量的值。

  • 表达式

标准(内建的)字串判断(不区分大小写):
a == b; a != b

另外的不区分大小写的字串判断(使用 System.dll):
a S< b; a S>= b; a S> b; a S<= b
- 需要在 !include LogicLib.nsh 之前 !define LOGICLIB_STRCMP

区分大小写字串判断(使用 System.dll):
a S== b; a S!= b
- 需要在 !include LogicLib.nsh 之前 !define LOGICLIB_STRCMP

标准(内建的)有符号整数判断:
a = b; a <> b; a < b; a >= b; a > b; a <= b

标准(内建的)无符号整数判断:
a U< b; a U>= b; a U> b; a U<= b

64位整数判断(使用System.dll):
a L= b; a L<> b; a L< b; a L>= b; a L> b; a L<= b
- 需要在 !include LogicLib.nsh 之前 !define LOGICLIB_INT64CMP

内建的NSIS标记判断:
${Abort};
${Errors};
${RebootFlag};
${Silent}

内建的 NSIS 其它判断:
${FileExists} a;

任何有条件的 NSIS 指令判断:
${Cmd} a;

区段标记判断:
${SectionIsSelected} a;
${SectionIsSectionGroup} a;
${SectionIsSectionGroupEnd} a;
${SectionIsBold} a;
${SectionIsReadOnly} a;
${SectionIsExpanded} a;
${SectionIsPartiallySelected} a;

posted @ 2012-05-15 09:43 Mumoo 阅读(1543) | 评论 (0)编辑 收藏
 
头文件引用:
!include "LogicLib.nsh"

 基本语句

If|Unless..{ElseIf|ElseUnless}..[Else]..EndIf|EndUnless
- 有条件的执行一个语句区块,取决于表达式。

AndIf|AndUnless|OrIf|OrUnless
- 给 If, Unless, ElseIf 和 ElseUnless 增加额外的条件语句。

IfThen..|..|
- 有条件的执行一个内联语句,取决于表达式。

IfCmd..||..|
- 条件的执行一个内联语句,取决于 NSIS 函数提供的真值。

Select..{Case[2|3|4|5]}..[CaseElse|Default]..EndSelect
- 执行多个语句区块之一,取决于表达式的值。

Switch..{Case|CaseElse|Default}..EndSwitch
- 跳转到多个标记之一,取决于表达式的值。

Do[While|Until]..{ExitDo|Continue|Break}..Loop[While|Until]
- 重复一个语句区块直到停止 取决于表达式的值。

While..{ExitWhile|Continue|Break}..EndWhile
- DoWhile..Loop 的别名 (向后兼容)

For[Each]..{ExitFor|Continue|Break}..Next
- 重复语句区块来连续改变变量的值。

Goto
要跳转的标记 | +偏移| -偏移| 用户变量(目标地址)
如果指定了标记,则跳转到 “要跳转的标记:”。

如果指定了 +偏移 或 -偏移 ,跳转会根据偏移指令相对的跳转。Goto +1 跳转到下一条指令,Goto -1 跳转到上一条指令,等等。

Goto label
Goto +2
Goto -2
Goto $0

这是原生支持的跳转,利用跳转可以写循环。
posted @ 2012-05-14 10:30 Mumoo 阅读(5898) | 评论 (0)编辑 收藏
 

逻辑语句的宏文件: !include logiclib.nsh
IF语句:
   ${If} $0 == 'some value'
      MessageBox MB_OK '$$0 is some value'
   ${ElseIf} $0 == 'some other value'
      MessageBox MB_OK '$$0 is some other value'
   ${Else}
      MessageBox MB_OK '$$0 is "$0"'
     ${EndIf}

while循环:

   StrCpy $R1 0 ——————————字符串赋值为整型
   ${While} $R1 < 5
         IntOp $R1 $R1 + 1
         DetailPrint $R1——————————打印字符串
${EndWhile}

 

posted @ 2012-05-11 10:25 Mumoo 阅读(8973) | 评论 (0)编辑 收藏
 
!include logiclib.nsh

Var tmpInst
ReadRegStr $0 HKLM ${PRODUCT_INST_KEY} "InstallDir"
MessageBox MB_OK "tmpInst 有没有值: $0"

${If} $0 == ""
MessageBox MB_OK "没值"
${Else}
MessageBox MB_OK "有值"
${EndIf}
posted @ 2012-05-11 10:12 Mumoo 阅读(1911) | 评论 (0)编辑 收藏
 
; OpenReg.nsi
; 检查某注册表键是否存在的NSIS例子
; 编写:zhfi <zhfi1022@tom.com>
 
;--------------------------------
;定义注册表主键
!define HKEY_CLASSES_ROOT           0x80000000
!define HKEY_CURRENT_USER           0x80000001
!define HKEY_LOCAL_MACHINE          0x80000002
!define HKEY_USERS                  0x80000003
 
OutFile OpenReg.exe
 
XPStyle on
 
!include LogicLib.nsh
 
;--------------------------------
Name OpenReg
 
Section Nil
SectionEnd
 
Function .onInit
;为键的句柄创建一个缓存
System::Call "*(i 0) i .R0"
;将要检测的键放入内存中
Push "SOFTWARE\TENCENT\QQPinYin"
;调用API进行检查,返回值在$R1中
system::call 'Advapi32::RegOpenKey(i ${HKEY_LOCAL_MACHINE}, t s, i R0) .iR1'
;关闭该键的句柄
system::call 'Advapi32::RegCloseKey(i R0)'
;释放内存
system::free
;返回值:
;0代表键存在
;2代表键不存在
;其它值表示出错
${If} $R1 == 0
Contact usthis is my email signatureMessagebox mb_ok "Key Exists!"
${ElseIf} $R1 == 2
Messagebox mb_ok "Key doesn't Exists!"
${Else}
Messagebox mb_ok "Error!"
${EndIf}
Pop $R1
Pop $R0
Quit
FunctionEnd

posted @ 2012-05-09 16:12 Mumoo 阅读(1080) | 评论 (0)编辑 收藏
仅列出标题
共4页: 1 2 3 4