NSIS笔记
1、IfFileExists IfFileExists D:\SA\test\testdirectory\*.* 0 +1 判断testdirectory是否是一个目录,若是,则执行接下来的第一行代码,若不是,则执行下面的+2行代码。 IfFileExists $WINDIR\SysWOW64\msvcr100.dll 0 +2 判断$WINDIR\SysWOW64\msvcr100.dll文件是否存在,若存在,则执行接下来的第一行代码,若不存在,则执行下面的+3行代码。 重点:实测没有+1行存在
IfFileExists "$WINDIR\SysWOW64\msvcr100.dll" 0 +2
MessageBox MB_OK "msvcr100.dll存在!" #0
MessageBox MB_OK "msvcr100.dll阿萨斯大大!" #+2
MessageBox MB_OK "msvcr100.dll不存在!" #+3
2、执行进程 Exec "$INSTDIR\${VS2010_x86}"
3、检测某个盘的剩余空间 StrCpy $R1 $sSetupPath 2 #前2个字符为盘符
${DriveSpace} $R1 "/D=F /S=M" $R2
${If} $R2 < 540
StrCpy $R3 $R1 1
MessageBox MB_OK "{f 2}提示{/f}" "{f 2}$R3盘剩余空间不足,无法安装。{/f}"
goto InstallAbort
${Else}
#StrCpy $R3 $R1 1
#MessageBox MB_OK "$R3盘可用空间为 $R2 M。"
${EndIf}
4、判断操作系统版本 !include "WinVer.nsh" AtLeastWin<version> 检测是否高于指定版本
IsWin<version> 检测指定版本(唯一限定版本)
AtMostWin<version> 检测是否低于指定版本
<version> 允许的值:
95、98、ME、NT4、2000、XP、2003、Vista、2008、7、2008R2
例如:
${If} ${AtLeastWin7}
MessageBox MB_OK "系统为win7或以上系统!" ${EndIf}
5、判断是32位系统,还是64位系统
!include "x64.nsh" ${If} ${RunningX64}
MessageBox MB_OK "这是64位系统,在这写x64安装的东西"
${Else}
MessageBox MB_OK "这是32位系统,在这写x86安装的东西"
${EndIf}
6、设置duilib中的控件文本 nsNiuniuSkin::SetControlAttribute "install_time" "text" "{f 9}xxxx{/f}"
7、获取当前系统时间 System::Alloc 16
System::Call "kernel32::GetLocalTime(isR0)"
System::Call "*$R0(&i2.R1,&i2.R2,&i2,&i2.R4)"
System::Free $R0
MessageBox MB_OK "$R1年$R2月$R4日" 更详细: System::Alloc 16
System::Call kernel32::GetLocalTime(isR0)
System::Call *$R0(&i2.R1,&i2.R2,&i2.R3,&i2.R4,&i2.R5,&i2.R6,&i2.R7,&i2.R8)
System::Free $R0
MessageBox MB_OK "$R1年$R2月$R4日,星期$R3,$R5  R6  R7.$R8"
8、数学运算 #实现: ($R1-$R9)*365+($R2-$R8)*30+($R4-$R7)
System::Int64Op $R1 - $R9 #注意空格
Pop $R6
System::Int64Op $R6 * 365
Pop $R6 System::Int64Op $R2 - $R8
Pop $R5
System::Int64Op $R5 * 30
Pop $R5
System::Int64Op $R6 + $R5
Pop $R5 System::Int64Op $R4 - $R7
Pop $R6
System::Int64Op $R6 + $R5
Pop $R5
${If} $R5 == 0
StrCpy $R5 "1" #最小为0
${EndIf}
|