Page 2 of 2
Posted: Fri Nov 18, 2005 7:01 pm
by Trond
PB wrote:> I'm not sure if Vista and Longhorn works
@Fred: Maybe PureBasic's OSVersion() command can be updated to get
these versions of Windows too?

If there should be separate detection for Longhorn, why not make a separate detection for Chicago as well? I'd suggest that you ignore internal codenames.
Posted: Sat Nov 19, 2005 12:03 am
by techjunkie
Trond wrote:PB wrote:> I'm not sure if Vista and Longhorn works
@Fred: Maybe PureBasic's OSVersion() command can be updated to get
these versions of Windows too?

If there should be separate detection for Longhorn, why not make a separate detection for Chicago as well? I'd suggest that you ignore internal codenames.
Both Windows Vista and Windows Server "Loghorn" are official names by now, but the server is released in 2007 so I'll guess it can change.
(It would be nice to get the result for all 7 - 9 different Vista versions)
http://www.microsoft.com/windowsvista/default.mspx
http://www.microsoft.com/windowsserver2 ... .mspx#EFAA
Posted: Thu Jan 05, 2006 2:07 am
by sverson
Code: Select all
;/ Getting the System Version
;/ http://msdn.microsoft.com/library/Default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
;/
;/ Windows 95 B: OK
;/ Windows 98 SE: OK
;/ Windows ME: OK
;/ Windows NT4 SP6a: OK
;/ Windows 2000 Pro SP4: OK
;/ Windows XP Pro SP2: OK
#BUFSIZE = 80
#VER_NT_WORKSTATION = 1
#VER_NT_DOMAIN_CONTROLLER = 2
#VER_NT_SERVER = 3
#PROCESSOR_ARCHITECTURE_INTEL = 0
#PROCESSOR_ARCHITECTURE_MIPS = 1
#PROCESSOR_ARCHITECTURE_ALPHA = 2
#PROCESSOR_ARCHITECTURE_PPC = 3
#PROCESSOR_ARCHITECTURE_SHX = 4
#PROCESSOR_ARCHITECTURE_ARM = 5
#PROCESSOR_ARCHITECTURE_IA64 = 6
#PROCESSOR_ARCHITECTURE_ALPHA64 = 7
#PROCESSOR_ARCHITECTURE_MSIL = 8
#PROCESSOR_ARCHITECTURE_AMD64 = 9
#PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF
#SM_SERVERR2 = 89
#VER_SUITE_SMALLBUSINESS = 1
#VER_SUITE_ENTERPRISE = 2
#VER_SUITE_BACKOFFICE = 4
#VER_SUITE_COMMUNICATIONS = 8
#VER_SUITE_TERMINAL = 10
#VER_SUITE_SMALLBUSINESS_RESTRICTED = 20
#VER_SUITE_EMBEDDEDNT = 40
#VER_SUITE_DATACENTER = 80
#VER_SUITE_SINGLEUSERTS = 100
#VER_SUITE_PERSONAL = 200
#VER_SUITE_BLADE = 400
Structure OSVERSIONINFOEX Extends OSVERSIONINFO ;/ -> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/osversioninfoex_str.asp
wServicePackMajor.w ; Major version number of the latest Service Pack installed on the system.
wServicePackMinor.w ; Minor version number of the latest Service Pack installed on the system.
wSuiteMask.w ; Bit flags that identify the product suites available on the system.
wProductType.b ; Additional information about the system.
wReserved.b ; Reserved for future use.
EndStructure
Procedure.s WindowsVersion()
Protected Version.OSVERSIONINFOEX, SystemInfo.SYSTEM_INFO, *pGetNativeSystemInfo, bOsVersionInfoEx.b
Protected WinVer$, hkey.l
; Try calling GetVersionEx using the OSVERSIONINFOEX Structure.
; If that fails, Try using the OSVERSIONINFO Structure.
ZeroMemory_(@Version, SizeOf(OSVERSIONINFOEX))
Version\dwOSVersionInfoSize=SizeOf(OSVERSIONINFOEX)
bOsVersionInfoEx = GetVersionEx_(Version)
If bOsVersionInfoEx=0
ZeroMemory_(@Version, SizeOf(OSVERSIONINFO))
Version\dwOSVersionInfoSize=SizeOf(OSVERSIONINFO)
If GetVersionEx_(Version)=0
ProcedureReturn "ERROR 1"
EndIf
EndIf
Select Version\dwPlatformId
Case #VER_PLATFORM_WIN32_NT ; Test for the Windows NT product family.
; test For the specific product.
If (Version\dwMajorVersion=6) And (Version\dwMinorVersion=0)
If Version\wProductType = #VER_NT_WORKSTATION
WinVer$ = "Microsoft Windows Vista "
Else
WinVer$ = "Windows Server 'Longhorn' "
EndIf
EndIf
If (Version\dwMajorVersion=5) And (Version\dwMinorVersion=2)
; Use GetProcAddress To avoid load issues on Windows 2000
*pGetNativeSystemInfo = GetProcAddress_(GetModuleHandle_("kernel32.dll"), "GetNativeSystemInfo")
If *pGetNativeSystemInfo
CallFunctionFast(*pGetNativeSystemInfo,@SystemInfo)
If GetSystemMetrics_(#SM_SERVERR2)
WinVer$ = "Microsoft Windows Server 2003 'R2' "
ElseIf (Version\wProductType =#VER_NT_WORKSTATION) And (SystemInfo\wProcessorArchitecture=#PROCESSOR_ARCHITECTURE_AMD64)
WinVer$ = "Microsoft Windows XP Professional x64 Edition "
Else
WinVer$ = "Microsoft Windows Server 2003, "
EndIf
EndIf
EndIf
If (Version\dwMajorVersion=5) And (Version\dwMinorVersion=1)
WinVer$ = "Microsoft Windows XP "
EndIf
If (Version\dwMajorVersion=5) And (Version\dwMinorVersion=0)
WinVer$ = "Microsoft Windows 2000 "
EndIf
If (Version\dwMajorVersion<=4)
WinVer$ = "Microsoft Windows NT "
EndIf
; test For specific product on Windows NT 4.0 SP6 And later.
If bOsVersionInfoEx
If (Version\wProductType=#VER_NT_WORKSTATION) And (SystemInfo\wProcessorArchitecture<>#PROCESSOR_ARCHITECTURE_AMD64)
If (Version\dwMajorVersion=4)
WinVer$ + "Workstation 4.0 "
ElseIf (Version\wSuiteMask & #VER_SUITE_PERSONAL)
WinVer$ + "Home Edition "
Else
WinVer$ + "Professional "
EndIf
; Test for the server type.
ElseIf (Version\wProductType=#VER_NT_SERVER) Or (Version\wProductType=#VER_NT_DOMAIN_CONTROLLER)
If (Version\dwMajorVersion=5) And (Version\dwMinorVersion=2)
If (SystemInfo\wProcessorArchitecture<>#PROCESSOR_ARCHITECTURE_IA64)
If (Version\wSuiteMask & #VER_SUITE_DATACENTER)
WinVer$ + "Datacenter Edition for Itanium-based Systems"
ElseIf (Version\wSuiteMask & #VER_SUITE_ENTERPRISE)
WinVer$ + "Enterprise Edition for Itanium-based Systems"
EndIf
ElseIf (SystemInfo\wProcessorArchitecture<>#PROCESSOR_ARCHITECTURE_AMD64)
If (Version\wSuiteMask & #VER_SUITE_DATACENTER)
WinVer$ + "Datacenter x64 Edition "
ElseIf (Version\wSuiteMask & #VER_SUITE_ENTERPRISE)
WinVer$ + "Enterprise x64 Edition "
Else
WinVer$ + "Standard x64 Edition "
EndIf
Else
If (Version\wSuiteMask & #VER_SUITE_DATACENTER)
WinVer$ + "Datacenter Edition "
ElseIf (Version\wSuiteMask & #VER_SUITE_ENTERPRISE)
WinVer$ + "Enterprise Edition "
ElseIf (Version\wSuiteMask & #VER_SUITE_BLADE)
WinVer$ + "Web Edition "
Else
WinVer$ + "Standard Edition "
EndIf
EndIf
ElseIf (Version\dwMajorVersion=5) And (Version\dwMinorVersion=0)
If (Version\wSuiteMask & #VER_SUITE_DATACENTER)
WinVer$ + "Datacenter Server "
ElseIf (Version\wSuiteMask & #VER_SUITE_ENTERPRISE)
WinVer$ + "Advanced Server "
Else
WinVer$ + "Server "
EndIf
Else ; Windows NT 4.0
If (Version\wSuiteMask & #VER_SUITE_ENTERPRISE)
WinVer$ + "Server 4.0, Enterprise Edition "
Else
WinVer$ + "Server 4.0 "
EndIf
EndIf
EndIf
Else ; Test for specific product on Windows NT 4.0 SP5 and earlier
szProductType.s = Space(#BUFSIZE)
dwBufLen.l = #BUFSIZE
lRet.l = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,"SYSTEM\CurrentControlSet\Control\ProductOptions",0,#KEY_QUERY_VALUE, @hkey)
If (lRet<>#ERROR_SUCCESS)
ProcedureReturn "ERROR 2"
EndIf
lRet = RegQueryValueEx_( hkey,"ProductType", 0, 0, @szProductType, @dwBufLen)
RegCloseKey_(hkey)
If (lRet<>#ERROR_SUCCESS) Or (dwBufLen > #BUFSIZE)
ProcedureReturn "ERROR 3"
EndIf
If szProductType="WINNT" : WinVer$ + "Workstation " : EndIf
If szProductType="LANMANNT" : WinVer$ + "Server " : EndIf
If szProductType="SERVERNT" : WinVer$ + "Advanced Server " : EndIf
WinVer$ + Str(Version\dwMajorVersion) + "." + Str(Version\dwMinorVersion)
EndIf
; Display service pack (if any) and build number.
If (Version\dwMajorVersion=4) And (PeekS(@Version\szCSDVersion,128) = "Service Pack 6")
lRet.l = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\Q246009",0,#KEY_QUERY_VALUE, @hkey)
If (lRet=#ERROR_SUCCESS)
WinVer$ + "Service Pack 6a (Build " + Str(Version\dwBuildNumber & $FFFF) + ")"
Else ; Windows NT 4.0 prior to SP6a
WinVer$ + PeekS(@Version\szCSDVersion,128) + " (Build " + Str(Version\dwBuildNumber & $FFFF) + ")"
EndIf
RegCloseKey_(hkey)
Else ; not Windows NT 4.0
WinVer$ + PeekS(@Version\szCSDVersion,128) + " (Build " + Str(Version\dwBuildNumber & $FFFF) + ")"
EndIf
Case #VER_PLATFORM_WIN32_WINDOWS ; Test for the Windows Me/98/95.
If (Version\dwMajorVersion=4) And (Version\dwMinorVersion=0)
WinVer$ = "Microsoft Windows 95 "
If (PeekS(@Version\szCSDVersion+1,1)="B") Or (PeekS(@Version\szCSDVersion+1,1)="C")
WinVer$ + "OSR2"
EndIf
EndIf
If (Version\dwMajorVersion=4) And (Version\dwMinorVersion=10)
WinVer$ = "Microsoft Windows 98 "
If (PeekS(@Version\szCSDVersion+1,1)="A") Or (PeekS(@Version\szCSDVersion+1,1)="B")
WinVer$ + "SE"
EndIf
EndIf
If (Version\dwMajorVersion=4) And (Version\dwMinorVersion=90)
WinVer$ = "Microsoft Windows Millenium Edition"
EndIf
Case #VER_PLATFORM_WIN32s
WinVer$ = "Microsoft Win32s"
EndSelect
ProcedureReturn WinVer$
EndProcedure
MessageRequester("Windows Version",WindowsVersion())
End

sverson