欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

NSIS 打包记要

程序员文章站 2024-02-03 22:09:28
...

NSIS 网上介绍比较多,这里贴几个方向的链接,不再赘述;

  1. 入门使用介绍的,推荐链接:https://www.cnblogs.com/zzllily/articles/5443850.html

  2. 插件使用说明的,推荐链接:http://https://nsis.sourceforge.io/Builtin_NSISdl_plug-in

  3. 内置函数多查用户手册

  4. SetDetailsPrint的使用
    SetDetailsPrint textonly 设置显示文件到进度条
    SetDetailsPrint listonly 设置显示文件到列表
    NSIS 打包记要

  5. 进度条 进度和 安装section的代码行数相关,如果section内调用函数,则只算一行的进展,这样可以控制每个section完成后,进度条的位置
    NSIS 打包记要

  6. 如何检测word是否安装

    !define KEY_WORD_2007 "SOFTWARE\Microsoft\Office\12.0\Word\InstallRoot"
    !define KEY_WORD_2010 "SOFTWARE\Microsoft\Office\14.0\Word\InstallRoot"
    !define KEY_WORD_2013 "SOFTWARE\Microsoft\Office\15.0\Word\InstallRoot"
    !define KEY_WORD_2016 "SOFTWARE\Microsoft\Office\16.0\Word\InstallRoot"
    
    Function CheckWordVersion
        SetRegView 64
        MessageBox MB_ICONINFORMATION|MB_OK 'word2007_x64'
        ReadRegStr $0 HKLM ${KEY_WORD_2007} "Path"
        StrCmp $0 "" word2010_x64 WordExist
        word2010_x64:
        MessageBox MB_ICONINFORMATION|MB_OK 'word2010_x64'
        ReadRegStr $0 HKLM ${KEY_WORD_2010} "Path"
        StrCmp $0 "" word2013_x64 WordExist
        word2013_x64:
        MessageBox MB_ICONINFORMATION|MB_OK 'word2013_x64'
        ReadRegStr $0 HKLM ${KEY_WORD_2013} "Path"
        StrCmp $0 "" word2016_x64 WordExist
        word2016_x64:
        MessageBox MB_ICONINFORMATION|MB_OK 'word2016_x64'
        ReadRegStr $0 HKLM ${KEY_WORD_2016} "Path"
        StrCmp $0 "" word2007_x32 WordExist
        word2007_x32:
        SetRegView 32
      Push ${KEY_WORD_2007}
        MessageBox MB_ICONINFORMATION|MB_OK 'word2007_x32'
        ReadRegStr $0 HKLM ${KEY_WORD_2007} "Path"
        StrCmp $0 "" word2010_x32 WordExist
        word2010_x32:
        MessageBox MB_ICONINFORMATION|MB_OK 'word2010_x32'
        ReadRegStr $0 HKLM ${KEY_WORD_2010} "Path"
        StrCmp $0 "" word2013_x32 WordExist
        word2013_x32:
        MessageBox MB_ICONINFORMATION|MB_OK 'word2013_x32'
        ReadRegStr $0 HKLM ${KEY_WORD_2013} "Path"
        StrCmp $0 "" word2016_x32 WordExist
        word2016_x32:
        MessageBox MB_ICONINFORMATION|MB_OK 'word2016_x32'
        ReadRegStr $0 HKLM ${KEY_WORD_2016} "Path"
        StrCmp $0 "" WordNotExist WordExist
        WordExist:
        Goto CheckWordVersionExit
        WordNotExist:
        MessageBox MB_ICONINFORMATION|MB_OK "请检查及安装相应Word软件。"
        CheckWordVersionExit:
    FunctionEnd
    
  7. 检测.net 4.0是否安装,未安装则下载安装

    Function checkFramework4
        ClearErrors
        ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Install"
        StrCmp $0 1 0 +3
        Goto ExitCheckFramework4
        DetailPrint "检测到您设备上还未安装.NET4.0,准备下载安装..."
        call DownloadNetFramework45
        ExitCheckFramework4:
    FunctionEnd
    
    Function DownloadNetFramework45
      ;下载 .NET Framework 4.5
      DetailPrint "开始下载 .NET Framework 4.5.2 ..."
      NSISdl::download /TRANSLATE2 '正在下载 %s' '正在连接...' '(剩余 1 秒)' '(剩余 1 分钟)' '(剩余 1 小时)' '(剩余 %u 秒)' '(剩余 %u 分钟)' '(剩余 %u 小时)' '已完成:%skB(%d%%) 大小:%skB 速度:%u.%01ukB/s' /TIMEOUT=7500 /NOIEPROXY 'http://download.microsoft.com/download/E/2/1/E21644B5-2DF2-47C2-91BD-63C560427900/NDP452-KB2901907-x86-x64-AllOS-ENU.exe' '$TEMP\NDP452-KB2901907-x86-x64-AllOS-ENU.exe'
      Pop $R0
      StrCmp $R0 "success" 0 +2
    
      SetDetailsPrint textonly
      DetailPrint "正在安装 .NET Framework 4.5.2 ..."
      SetDetailsPrint listonly
      ExecWait '$TEMP\NDP452-KB2901907-x86-x64-AllOS-ENU.exe /quiet /norestart' $R1
      Delete "$TEMP\NDP452-KB2901907-x86-x64-AllOS-ENU.exe"
    FunctionEnd
    

.