Version plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
Line 41: Line 41:
<highlight-nsis>
<highlight-nsis>


; if "version.dll" copied in NSIS plugin sub-directory
Name VersionExample
; this line is not necessary


!addplugindir "plugins"
# Included files
!include Sections.nsh
!include "LogicLib.nsh"


OutFile "Example_Version_NSIS_plugin.exe"


; it is not example
#Declare variables
; it is for this empty intallation only
var isWindowsXP
 
OutFile "example_Version_NSIS_plugin.exe"
 
 
Section Dummy
; it is not example
; it is for this empty intallation only
SectionEnd
 
 
; variables declaration
 
var TempResult
var MajorVersion
var MajorVersion
var MinorVersion
var MinorVersion
Line 67: Line 56:
var PlatformID
var PlatformID
var CSDVersion
var CSDVersion
var ProductType


Section -Nope
#Nothing to do here
SectionEnd


Function .onInit
Function .onInit


   ; detect Windows XP
   #detect Windows XP
  ; it is simply
 
  ; call plugin dll function
 
   Version::IsWindowsXP
   Version::IsWindowsXP
 
   #obtain value
   ; get result
   Pop $isWindowsXP
 
    
   Pop $TempResult
   ${if} $isWindowsXP == "1"
 
    MessageBox MB_OK "Its Windows XP!"
   ; check result
   ${Else}
 
    MessageBox MB_OK "Its not Windows XP!"
   StrCmp $TempResult "1" ItIsWindowsXP IsIsNotWindowsXP
   ${EndIf}
 
    
  ItIsWindowsXP:
   #call plugin dll function  
  MessageBox MB_OK "This OS is Windows XP"
   Goto Go2
 
  IsIsNotWindowsXP:
  MessageBox MB_OK "This OS is not Windows XP"
   Goto Go2
 
 
   ; get Windows OS version info
 
   Go2:
 
  ; call plugin dll function  
 
   Version::GetWindowsVersion
   Version::GetWindowsVersion
  ; get result


   Pop $MajorVersion
   Pop $MajorVersion
Line 110: Line 84:
   Pop $PlatformID
   Pop $PlatformID
   Pop $CSDVersion
   Pop $CSDVersion
  Pop $ProductType


   ; show result
   ${if} $ProductType == "1"
   MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion"
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, Workstation"
 
   ${ElseIf} $ProductType == "2"
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, DomainController"
  ${ElseIf} $ProductType == "3"
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, Server"
  ${Else}
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, Unknown ProductType"
  ${EndIf}
  Quit
 
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>


[[Category:Plugins]]
[[Category:Plugins]]

Revision as of 16:36, 20 February 2013

Author: denis_gorbunov,PageAuthor (talk, contrib)


Links

Version 0.3 (20. feb 2013)
NSIS_version_plugin_03.zip (69 KB)

Release builds with VS2010 Premium (only older 0.2 release)

ANSI: http://db.tt/cbyN0KJh Unicode: http://db.tt/OfllzHW7

Description

With this plugin you are able to determine which version of windows you are running. Technically it is using the GetVersionEx() method from the "kernel32.dll".

Features:

  • check for a specific windows version:
    • IsWindows95
    • IsWindows98
    • IsWindowsME
    • IsWindowsNT351
    • IsWindowsNT40
    • IsWindows2000
    • IsWindowsXP
    • IsWindows2003
    • IsWindowsXPx64
    • IsWindowsVista
    • IsWindowsServer2008
    • IsWindows7
    • IsWindowsServer2008R2
    • IsWindows8
    • IsWindowsServer2012
  • get all relevant windows versioning information by calling the 'GetWindowsVersion' method:
    • major version
    • minor version
    • build number
    • platform id
    • service pack name
    • product type
  • detect the windows platform type by calling 'IsWindowsPlatformNT()' or 'IsWindowsPlatform9x'

Usage Example

Name VersionExample
 
# Included files
!include Sections.nsh
!include "LogicLib.nsh"
 
OutFile "Example_Version_NSIS_plugin.exe"
 
#Declare variables
var isWindowsXP
var MajorVersion
var MinorVersion
var BuildNumber
var PlatformID
var CSDVersion
var ProductType 
 
 
Section -Nope
#Nothing to do here
SectionEnd
 
Function .onInit
 
  #detect Windows XP
  Version::IsWindowsXP
  #obtain value
  Pop $isWindowsXP
 
  ${if} $isWindowsXP == "1"
    MessageBox MB_OK "Its Windows XP!"
  ${Else}
    MessageBox MB_OK "Its not Windows XP!"
  ${EndIf}
 
  #call plugin dll function 
  Version::GetWindowsVersion

  Pop $MajorVersion
  Pop $MinorVersion
  Pop $BuildNumber
  Pop $PlatformID
  Pop $CSDVersion
  Pop $ProductType
 
  ${if} $ProductType == "1"
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, Workstation"
  ${ElseIf} $ProductType == "2"
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, DomainController"
  ${ElseIf} $ProductType == "3"
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, Server"
  ${Else}
    MessageBox MB_OK "$PlatformID-platform, version $MajorVersion.$MinorVersion, build $BuildNumber, $CSDVersion, Unknown ProductType"
  ${EndIf}
  Quit
 
FunctionEnd