nsis installation package production

nsis

nsis download:https://www.filehorse.com/download-nsis/

Similar to the nsis packaging tool, there is inno setup, but nsis is more powerful and innosetup is more convenient for debugging.

Script

nsis script*.nsi

Name HealthSystem
OutFile "HealthSystem.exe"

InstallDir $PROGRAMFILES64\HealthSystem
RequestExecutionLevel admin

Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

!define PRODUCT_INSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Install\HealthSystem"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\HealthSystem"
InstallDirRegKey HKLM "${PRODUCT_INSTALL_KEY}" "HealthSystem"

unction .onInit
    ClearErrors
    ExecShellWait "net stop mysql && sc delete mysql" SW_HIDE   #ExecWait执行可以看到控制台

    RMDir /r $INSTDIR
    Delete $DESKTOP\HealthSystem.lnk
FunctionEnd

Section #生成控制面板信息
	WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "HealthSystem"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayVersion" "1.0"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "Test"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\UIEngineMonitor.ico"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\Uninstall.exe"
    WriteUninstaller $INSTDIR\Uninstall.exe    #调用uninstall section生成unistall.exe
SectionEnd

Section Mysql                 #拷贝mysql安装部署
    SetOutPath $PROGRAMFILES64\mysql
    SetOverwrite on
    File /r /x *.pdb /x *.lib .\mysql-8.0.28-winx64\*

	SetOutPath $PROGRAMFILES64\dotnet    #可以设置多个输出,注释使用#符号
    SetOverwrite on
    File /r /x *.pdb /x *.lib .\dotnet

    ClearErrors
    FileOpen $0 $PROGRAMFILES64\mysql\my.ini w
    FileSeek $0 0 END
    IfErrors done
    FileWrite $0 "[client]$\r$\ndefault-character-set=utf8$\r$\n[mysqld]$\r$\nport=3306$\r$\n"
    FileWrite $0 "basedir=$\"$PROGRAMFILES64/mysql$\"$\r$\n"
    FileWrite $0 "datadir=$\"$PROGRAMFILES64/mysql/data$\"$\r$\n"
    FileWrite $0 "character-set-server=utf8$\r$\ndefault-storage-engine=INNODB$\r$\nmax_connections=200$\r$\n"
    FileClose $0
    done:

    ExecWait "cmd /c cd /d $PROGRAMFILES64\mysql\bin && mysqld.exe --install && sc config mysql start=delayed-auto && net start mysql"
SectionEnd

Section Uninstall    #必须调用WriteUninstaller生成exe
    ClearErrors
    nsExec::Exec "cmd /c sc delete mysql"
    RMDir /r $INSTDIR
    RMDir /r $PROGRAMFILES64\mysql
    Delete $DESKTOP\HealthSystem.lnk
SectionEnd
  • section, as an option on the component page, can be selected and set individually
  • function, execute function

After installing nsis, right-click the file to run the nsi script. After modifying the file, reload the script to automatically run the script.
Insert image description here


execute wait

ExecWait "$INSTDIR\nsis.bat"                         //可以等待,不可以隐藏窗口 
nsExec::Exec "$INSTDIR\nsis.bat"                    //可以等待,可以隐藏窗口
ExecShell Open "$INSTDIR\nsis.bat" "" SW_HIDE      // 不可以等待,可以隐藏窗口
ExecCmd::exec "$INSTDIR\nsis.bat"                 // 不可以等待 ,可以隐藏窗口 

Guess you like

Origin blog.csdn.net/daoer_sofu/article/details/130700548