NSIS是个十分好用的打包工具,工作中常用到AutoCAD软件,出于某些原因,我需要使用NSIS来获取AutoCAD的安装路径。
经过对注册表的一番查看,写出代码如下:
01 #可自行扩展,比如需要安装AutoCAD字体时,需要找到AutoCAD的安装路径等 02 03 Page instfiles 04 05 ShowInstDetails show 06 07 Var regCount 08 Var subCount 09 Var regKeyName 10 Var subKeyName 11 Var acadLocation 12 13 Section 14 15 SetRegView 64 16 StrCpy $regCount 0 17 StrCpy $subCount 0 18 19 loop: 20 EnumRegKey $regKeyName HKEY_LOCAL_MACHINE SOFTWARE\Autodesk\AutoCAD $regCount 21 IntOp $regCount $regCount + 1 22 StrCmp $regKeyName "" done 23 24 loop_sub: 25 EnumRegKey $subKeyName HKEY_LOCAL_MACHINE SOFTWARE\Autodesk\AutoCAD\$regKeyName $subCount 26 IntOp $subCount $subCount + 1 27 StrCmp $subKeyName "" loop 28 ReadRegStr $acadLocation HKEY_LOCAL_MACHINE SOFTWARE\Autodesk\AutoCAD\$regKeyName\$subKeyName "Location" 29 StrCmp $acadLocation "" loop_sub 30 31 done: 32 DetailPrint $acadLocation 33 34 SectionEnd
可以将其修改为头文件,方便以后编写关于AutoCAD程序时进行引用:
01 Var regCount 02 Var subCount 03 Var regKeyName 04 Var subKeyName 05 Var acadLocation 06 07 !define GetLocation `!insertmacro GetLocation` 08 !macro GetLocation 09 SetRegView 64 10 StrCpy $regCount 0 11 StrCpy $subCount 0 12 13 loop: 14 EnumRegKey $regKeyName HKEY_LOCAL_MACHINE SOFTWARE\Autodesk\AutoCAD $regCount 15 IntOp $regCount $regCount + 1 16 StrCmp $regKeyName "" done 17 18 loop_sub: 19 EnumRegKey $subKeyName HKEY_LOCAL_MACHINE SOFTWARE\Autodesk\AutoCAD\$regKeyName $subCount 20 IntOp $subCount $subCount + 1 21 StrCmp $subKeyName "" loop 22 ReadRegStr $acadLocation HKEY_LOCAL_MACHINE SOFTWARE\Autodesk\AutoCAD\$regKeyName\$subKeyName "Location" 23 StrCmp $acadLocation "" loop_sub 24 25 done: 26 Push $acadLocation 27 !macroend