这段时间在学习nsis打包,遇到了一个问题,nsis脚本设置.net运行环境问题,在网上看了不少教程,但都不完整,这里给出一个我觉得判断.net版本的连接:http://blog.youkuaiyun.com/aqtata/article/details/51814602这里是分版本判断电脑的.net是否安装,有了判断.net是否安装的方法,剩下的就是调用,网上给出了很多调用此方法的例子,如:
Section -.NET
Call GetNetFrameworkVersion
Pop
R1
{If} $R1 > ‘4.0.30319’
MessageBox MB_OK ‘需要net4’
SectionEnd
网上很多方法都是直接获取版本号去对比,但实际上这样用在电脑中.NET版本大于“4.0.30319”并不能在安装时时候弹框,我在这里掉坑里很久,可能自己比较菜吧,后来发现直接比较并不行,需要使用NSIS对比版本号方法:
Function VersionCheckV5
Exch R0;secondversionnumberExchExch R1 ; first version number
Push R2Push R3
Push R4Push R5 ; second version part
Push $R6 ; first version part
StrCpy
R1
R1.
StrCpy
R0
R0.
Next: StrCmp
R0
R1 “” 0 +3
StrCpy $R0 0
Goto Done
StrCmp
R0“”0+2StrCpy
R0 0.
StrCmp
R1“”0+2StrCpy
R1 0.
StrCpy
R20IntOp
R2
R2+1StrCpy
R4
R11
R2
StrCmp
R4.0−2StrCpy
R6
R1
R2
IntOp
R2
R2 + 1
StrCpy
R1
R1 “” $R2
StrCpy
R20IntOp
R2
R2+1StrCpy
R4
R01
R2
StrCmp
R4.0−2StrCpy
R5
R0
R2
IntOp
R2
R2 + 1
StrCpy
R0
R0 “” $R2
IntCmp R50CompareIntCmp R6 0 Compare
StrCpy
R30StrCpy
R4
R61
R3
IntOp
R3
R3 + 1
StrCmp $R4 0 -2
StrCpy
R20StrCpy
R4
R51
R2
IntOp
R2
R2 + 1
StrCmp $R4 0 -2
IntCmp
R3
R2 0 +2 +4
Compare: IntCmp 1
R51
R6 Next 0 +3
StrCpy
R01GotoDoneStrCpy
R0 2
Done:
Pop
R6Pop
R5
Pop
R4Pop
R3
Pop
R2Pop
R1
Exch $R0 ; output
FunctionEnd
其具体如何调用,这里给出调用方法:
Function .onInit
;禁止多次安装实例 start
Call GetNetCLR4Version
Pop $R1
StrCpy $0 "4.0.30319"
Push $R1
Push $0
Call VersionCheckV5
Pop $R2 ;1电脑所用版本大,2电脑所用版本不符合条件,0 电脑所用版本符合
;MessageBox MB_OK $R2
${If} $R2 <= 1
MessageBox MB_OK "满足条件"
${Else}
MessageBox MB_OK "须安装,net4后,再安装此软件!"
${EndIf}
FunctionEnd
首先是调用获取.NET版本的方法获取版本,存放在
R1中,将待对比的版本号存放在
0中,Push
R1Push
0
Call VersionCheckV5
Pop
R2这是调用对比版本号方法,其中
R1,
0为输入参数,
R2 为返回值,将$R2 与1进行对比,即可得出是否满足条件 。