NSIS 從 WINDOWS登錄資料庫(REGEDIT.EXE) 檢查 .NET FRAMEWORK 和 .NET6 是否有安裝 (nsis check if registry key exists / nsis registry key exists)

NSIS 從 WINDOWS登錄資料庫(REGEDIT.EXE) 檢查 .NET FRAMEWORK 和 .NET6 是否有安裝 (nsis check if registry key exists / nsis registry key exists)

NSIS 從 WINDOWS登錄資料庫(REGEDIT.EXE) 檢查 .NET FRAMEWORK 和 .NET6 是否有安裝 (nsis check if registry key exists / nsis registry key exists)


資料來源:

https://stackoverflow.com/questions/27839860/nsis-check-if-registry-key-value-exists
https://stackoverflow.com/questions/15227634/check-for-net4-5-with-nsis
https://learn.microsoft.com/en-us/answers/questions/913327/correct-approach-to-check-for-net-6-installation.html


GITHUB: https://github.com/jash-git/NSIS_TEST_Project/tree/main/NSIS_REGEDIT_TEST


01.讀取『登錄資料庫(REGEDIT.EXE) 檢查 .NET FRAMEWORK 和 .NET6 是否有安裝』基礎語法

	Push $1
	Push $0
	ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Install"
;
;	
	Push $1
	Push $0
	ReadRegDWORD $0 HKLM "SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.WindowsDesktop.App" "6.0.8"
	ReadRegDWORD $1 HKLM "SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x86\sharedfx\Microsoft.WindowsDesktop.App" "6.0.8"

02.完整.NET6安裝與否測試語法:

; 該指令檔使用 HM VNISEdit 指令檔編輯器精靈產生

; 安裝程式初始定義常量
!define PRODUCT_NAME "NSIS check NET6";jash modify
!define PRODUCT_VERSION "v1001";jash modify
!define PRODUCT_PUBLISHER "VTEAM, Inc.";jash modify
!define PRODUCT_WEB_SITE "http://www.vteam.com.tw/";jash modify
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}";jash modify
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
BrandingText "Provided by VTEAM, Inc."  # 設置UI分割線上的文字。

SetCompressor /SOLID lzma

; ------ MUI 現代介面定義 (1.67 版本以上相容) ------
!include "MUI.nsh"

; MUI 預定義常量
!define MUI_ABORTWARNING
!define MUI_ICON "Release\a2cio-rv6es-001.ico";jash modify
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; 語言選擇視窗常量設定
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"

; 歡迎頁面
!insertmacro MUI_PAGE_WELCOME
; 授權合約頁面
;!insertmacro MUI_PAGE_LICENSE "..\..\..\path\to\licence\YourSoftwareLicence.txt"
; 安裝資料夾選擇頁面
!insertmacro MUI_PAGE_DIRECTORY
; 安裝過程頁面
!insertmacro MUI_PAGE_INSTFILES
; 安裝完成頁面
;!define MUI_FINISHPAGE_RUN "$INSTDIR\BCard_WCard_Generator.exe"
!insertmacro MUI_PAGE_FINISH

; 安裝卸載過程頁面
!insertmacro MUI_UNPAGE_INSTFILES

; 安裝介麵包含的語言設定
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "TradChinese"

; 安裝預釋放檔案
!insertmacro MUI_RESERVEFILE_LANGDLL
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 現代介面定義結束 ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME} ${PRODUCT_VERSION}.exe";jash modify
InstallDir "C:\NSIS_check_NET6";jash modify-因應有MySQL,所以已把安裝目錄放在C槽下,原本~ InstallDir "$PROGRAMFILES\SYRIS Workstation"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails show
ShowUnInstDetails show


Section "MainSection" SEC01
  SetOverwrite on
  SetOutPath "$INSTDIR"
  
  Push $1
  Push $0
  ReadRegDWORD $0 HKLM "SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.WindowsDesktop.App" "6.0.8"
  ReadRegDWORD $1 HKLM "SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x86\sharedfx\Microsoft.WindowsDesktop.App" "6.0.8"
  ${If} $0 == ""
	MessageBox MB_ICONINFORMATION|MB_OK "無安裝 .NET6 Runtime"
  ${Else}
  	MessageBox MB_ICONINFORMATION|MB_OK "有安裝 .NET6 Runtime"
	File "Release\a2cio-rv6es-001.ico";jash modify
  ${EndIf}  
SectionEnd

One thought on “NSIS 從 WINDOWS登錄資料庫(REGEDIT.EXE) 檢查 .NET FRAMEWORK 和 .NET6 是否有安裝 (nsis check if registry key exists / nsis registry key exists)

  1. nsis .net framework check

    How to Detect any .NET Framework – NSIS – SourceForge

    Check for .NET4.5+ with NSIS – Stack Overflow

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *