Page 1 of 1

Get Windows version with details

Posted: Thu May 28, 2009 1:18 pm
by doctorized
Here is a code that returns detailed info for Windows version.

Code: Select all

; Author: Wicker Man
; Date: May 22 2009
; OS: Windows
; Demo: No
; More codes at: www.geocities.com/kc2000labs/pb/pb.htm


DataSection 
CLSID_WbemLocator: 
    ;4590f811-1d3a-11d0-891f-00aa004b2e24 
Data.l $4590F811 
Data.w $1D3A, $11D0 
Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24 
IID_IWbemLocator: 
    ;dc12a687-737f-11cf-884d-00aa004b2e24 
Data.l $DC12A687 
Data.w $737F, $11CF 
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24 
IID_IUnknown: 
    ;00000000-0000-0000-C000-000000000046 
Data.l $00000000 
Data.w $0000, $0000 
Data.b $C0, $00, $00, $00, $00, $00, $00, $46 
IID_IWbemRefresher: 
;49353c99-516b-11d1-aea6-00c04fb68820 
Data.l $49353C99 
Data.w $516B, $11D1 
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20 
CLSID_WbemRefresher: 
;c71566f2-561E-11D1-AD87-00C04FD8FDFF 
Data.l $C71566F2 
Data.w $561E, $11D1 
Data.b $AD,$87,$00,$C0,$4F,$D8,$FD,$FF 
IID_IWbemConfigureRefresher: 
;49353c92-516b-11d1-aea6-00c04fb68820 
Data.l $49353C92 
Data.w $516B, $11D1 
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20 
IID_IWbemObjectAccess: 
;49353c9a-516b-11d1-aea6-00c04fb68820 
Data.l $49353C9A 
Data.w $516B, $11D1 
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20 
EndDataSection 


#COINIT_MULTITHREAD=0 
#RPC_C_AUTHN_LEVEL_CONNECT=2 
#RPC_C_IMP_LEVEL_IDENTIFY=2 
#EOAC_NONE=0 
#RPC_C_AUTHN_WINNT=10 
#RPC_C_AUTHZ_NONE=0 
#RPC_C_AUTHN_LEVEL_CALL=3 
#RPC_C_IMP_LEVEL_IMPERSONATE=3 
#CLSCTX_INPROC_SERVER=1 
#WBEM_S_NO_ERROR = 0 

Global OSCapabilities.s

Procedure.l ansi2bstr(ansi.s) 
  size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0) 
  Dim unicode.w(size) 
  MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size) 
  ProcedureReturn SysAllocString_(@unicode()) 
EndProcedure 

Procedure.s unicode2ansi(mem) 
  ansi.s="" 
  Repeat 
    a=PeekW(mem) 
    ansi=ansi+Chr(a) 
    mem+2 
  Until a=0 
  ProcedureReturn ansi 
EndProcedure 

Procedure.l CheckXP();Tell us if the OS is XP or not. Used to separate XP x64 from 2003 x83 as they have the same version number: 5.2.3790
CoInitializeEx_(0,#COINIT_MULTITHREAD) 
hres=CoInitializeSecurity_(0, -1,0,0,#RPC_C_AUTHN_LEVEL_CONNECT,#RPC_C_IMP_LEVEL_IDENTIFY,0,#EOAC_NONE,0) 
hres=CoCreateInstance_(?CLSID_WbemLocator,0,#CLSCTX_INPROC_SERVER,?IID_IWbemLocator,@loc.IWbemLocator) 
hres=loc\ConnectServer(ansi2bstr("root\cimv2"),0,0,0,0,0,0,@svc.IWbemServices) 
hres=svc\queryinterface(?IID_IUnknown,@pUnk.IUnknown) 
hres=CoSetProxyBlanket_(svc,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE) 
hres=CoSetProxyBlanket_(pUnk,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE) 
pUnk\release() 
hres=CoCreateInstance_(?CLSID_WbemRefresher,0,#CLSCTX_INPROC_SERVER,?IID_IWbemRefresher,@pRefresher.IWbemRefresher) 
hres=pRefresher\queryinterface(?IID_IWbemConfigureRefresher,@pConfig.IWbemConfigureRefresher) 
hres=pConfig\AddEnum(svc,ansi2bstr("Win32_OperatingSystem"),0,0,@penum.IWbemHiPerfEnum,@id) 
pConfig\release() 
Dim tab.IWbemObjectAccess(300) 
pRefresher\refresh(0) 
hres=penum\GetObjects(0,100*SizeOf(IWbemObjectAccess),@tab(),@retour.l) 
hres=tab(0)\GetPropertyHandle(ansi2bstr("Caption"),0,@caption)  

*MemoryID = AllocateMemory(500) 

For i=0 To retour-1 
  tab(i)\Readpropertyvalue(caption,500,@len,*MemoryID) 
  XPstring.s = unicode2ansi(*MemoryID)
  tab(i)\release() 
Next i 

FreeMemory(*MemoryID) 
penum\release() 
pRefresher\release(); 
svc\release() 
loc\release() 
CoUninitialize_()
If FindString(XPstring,"XP",1)
	ProcedureReturn 1
Else
	ProcedureReturn 0
EndIf
EndProcedure

Procedure.l IsWin64();Tell us if the OS is x64 or not.
*Is64 = 0
If OpenLibrary(0,"KERNEL32.DLL")
	*F = GetFunction(0,"IsWow64Process")
	If *F
		CallFunctionFast(*F,GetCurrentProcess_(), @*Is64)
	EndIf
	CloseLibrary(0)
EndIf
	If *Is64>0
		ProcedureReturn 1
	Else
		ProcedureReturn 0
	EndIf
EndProcedure

Procedure.s GetString(hKey.l, strPath.s, strValue.s, RegType.l=2)
OnErrorResume()
KeyHand.l:datatype.l:lResult.l
Dim strBuf.b(1):lDataBufSize.l
intZeroPos.l:tempV.l:mm.l
R = RegOpenKey_(hKey, strPath, @KeyHand)
lResult = RegQueryValueEx_(KeyHand, strValue, 0, @lValueType, 0, @lDataBufSize)
mm=lDataBufSize
If lDataBufSize > 0
	ReDim strBuf.b(lDataBufSize-1)
EndIf
lResult = RegQueryValueEx_(KeyHand, @strValue, 0, @RegType, @strBuf(), @lDataBufSize)
If lResult = #ERROR_SUCCESS
If lValueType = 4
tempV.l = 0
For i = 0 To lDataBufSize-1;Len(strBuf)
tempV = tempV + (strBuf(i) & $FF) * Pow(16,(2 * i))
Next
ProcedureReturn StrU(tempV,#Long)
EndIf
tmp.s
If RegType = #REG_MULTI_SZ
	For i=0 To lDataBufSize-1
		If strBuf(i)=0
			tmp + " , "
		Else
			tmp+ Chr(strBuf(i))
		EndIf
	Next
	For i=lDataBufSize-1 To 0 Step -1
		If Right(tmp,3)=" , ":tmp = Left(tmp,Len(tmp)-3):EndIf
	Next
	ProcedureReturn tmp + "."
EndIf
For i=0 To lDataBufSize-1
tmp+ Chr(strBuf(i))
Next
ProcedureReturn tmp
EndIf
EndProcedure

Procedure.s OSType()
Define.l m, mv, c, pd, miv
OSType.s: b.s
Global OS.OSVERSIONINFO
Global os1.OSVERSIONINFOEX
OS\dwOSVersionInfoSize = SizeOf(OS)    ; 'Assign some size to store the received information
GetVersionEx_(@OS)
If OS\dwPlatformId = 2; get some extra data under Windows NT and later
	os1\dwOSVersionInfoSize =SizeOf(os1)    ; 'Assign some size to store the received information
	GetVersionEx_(@os1)
	ReadEx = 1; extra data have been read
	mv = os1\dwMajorVersion
	pd = os1\dwPlatformId
	miv = os1\dwMinorVersion
	b = PeekS(@os1\szCSDVersion)
	c = os1\dwBuildNumber
	d = os1\wServicePackMajor
	E = os1\wServicePackMinor
	wPT = os1\wProductType 
	G = os1\wReserved
	SM = os1\wSuiteMask
Else
	mv = OS\dwMajorVersion
	pd = OS\dwPlatformId
	miv = OS\dwMinorVersion
	b = PeekS(@OS\szCSDVersion)
	c = OS\dwBuildNumber
EndIf
If OS\dwMajorVersion <> 0 
Check:
	If pd = 1
		If miv = 0 
			OSType = "Windows 95"
			If (c & $FFF) >= 1214 
			  OSType = OSType + " OSR 2.5": Goto RetOS
			EndIf
			If (c & $FFF) >= 1212 
				OSType = OSType + " OSR 2.1": Goto RetOS
			EndIf
			If (c & $FFF) = 1111
				OSType = OSType + " OSR 2": Goto RetOS
			EndIf
		EndIf
		If miv = 10 
			OSType = "Windows 98"
			If (c & $FFF) >= 2222 
				OSType = OSType + " Second Edition": Goto RetOS
			EndIf
			If (c & $FFF) >= 2000
				OSType = OSType + " SP1": Goto RetOS
			EndIf
		EndIf
		If miv = 90
			OSType = "Windows ME"
		EndIf
	ElseIf pd = 2 
		OSType = "Windows NT"
		If mv = 3 : OSType = OSType + " 3." + Str(miv):EndIf
		If mv = 4 : OSType = OSType + " 4.0":EndIf
		If mv = 5 
		  If miv = 0 : OSType = "Windows 2000":EndIf
		  If miv = 1 : OSType = "Windows XP":EndIf
		  If miv = 2 
		    If CheckXP() = 1; this is needed for XP x64 version
		      OSType = "Windows XP"
		    Else
		      OSType = "Windows Server 2003"
		    EndIf
		  EndIf
		EndIf
		If mv = 6 
			If miv = 0 
				OSType = "Windows Vista"
			Else
				OSType = "Windows Server 2008"
			EndIf
			If OSVersion() = #PB_OS_Windows_Server_2008 : OSType = "Windows Server 2008":EndIf
		EndIf
		If mv >= 6 ; for Vista, Server 2008 and future versions
			DLLhandle.l: ulProductType.l
			If OpenLibrary(0,"KERNEL32.DLL")
				*F = GetFunction(0,"GetProductInfo")
				If *F
					CallFunctionFast(*F,6,0,0,0,@ulProductType)
			
					Select (ulProductType)
					Case 6;; 'PRODUCT_BUSINESS
					OSType = OSType + " Business Edition"
					
					Case $10;; 'PRODUCT_BUSINESS_N
					OSType = OSType + " BusinessN Edition"
					
					Case $12;; 'PRODUCT_CLUSTER_SERVER
					OSType = OSType + " Cluster Server Edition"
					
					Case $8;; 'PRODUCT_DATACENTER_SERVER
					OSType = OSType + " Datacenter Edition (Full installation)"
					
					Case $C;; 'PRODUCT_DATACENTER_SERVER_CORE
					OSType = OSType + " Datacenter Edition (Server Core installation)"
					
					Case $4;; 'PRODUCT_ENTERPRISE
					OSType = OSType + " Enterprise Edition"
					
					Case $1B;; 'PRODUCT_ENTERPRISE_N
					OSType = OSType + " EnterpriseN Edition"
					
					Case $A;; 'PRODUCT_ENTERPRISE_SERVER
					OSType = OSType + " Enterprise Edition (Full installation)"
					
					Case $E;; 'PRODUCT_ENTERPRISE_SERVER_CORE
					OSType = OSType + " Enterprise Edition (Server Core installation)"
					
					Case $F;; 'PRODUCT_ENTERPRISE_SERVER_IA64
					OSType = OSType + " Datacenter Enterprise Edition for Itanium-based Systems"
					
					Case $2;; 'PRODUCT_HOME_BASIC
					OSType = OSType + " Home Basic Edition"
					
					Case $5;; 'PRODUCT_HOME_BASIC_N
					OSType = OSType + " Home BasicN Edition"
					
					Case $3;; 'PRODUCT_HOME_PREMIUM
					OSType = OSType + " Home Premium Edition"
					
					Case $1A; 'PRODUCT_HOME_PREMIUM_N
					OSType = OSType + " Home PremiumN Edition"
					
					Case $13; 'PRODUCT_HOME_SERVER
					OSType = OSType + " Home Server Edition"
					
					Case $18; 'PRODUCT_SERVER_FOR_SMALLBUSINESS
					OSType = OSType + " Server for Small Business Edition"
					
					Case $9; 'PRODUCT_SMALLBUSINESS_SERVER
					OSType = OSType + " Small Business Server Edition"
					
					Case $19; 'PRODUCT_SMALLBUSINESS_SERVER_PREMIUM
					OSType = OSType + " Small Business Server Premium Edition"
					
					Case $7; 'PRODUCT_STANDARD_SERVER
					OSType = OSType + " Standard Server Edition (Full installation)"
					
					Case $D; 'PRODUCT_STANDARD_SERVER_CORE
					OSType = OSType + " Standard Server Edition (Core installation)"
					
					Case $B; 'PRODUCT_STARTER
					OSType = OSType + " Starter Edition"
					
					Case $17; 'PRODUCT_STORAGE_ENTERPRISE_SERVER
					OSType = OSType + " Storage Server Enterprise Edition"
					
					Case $14; 'PRODUCT_STORAGE_EXPRESS_SERVER
					OSType = OSType + " Storage Express Server Edition"
					
					Case $15; 'PRODUCT_STORAGE_STANDARD_SERVER
					OSType = OSType + " Storage Standard Server Edition"
					
					Case $16; 'PRODUCT_STORAGE_WORKGROUP_SERVER
					OSType = OSType + " Storage Workgroup Server Edition"
					
					Case $1; 'PRODUCT_ULTIMATE
					OSType = OSType + " Ultimate Edition"
					
					Case $1C; 'PRODUCT_ULTIMATE
					OSType = OSType + " Ultimate Edition"
					
					Case $11; 'PRODUCT_WEB_SERVER
					OSType = OSType + " Web Server Edition"
					
					Default
					OSType = OSType + " Unknown Edition (" + Str(ulProductType) + ")"
					EndSelect
				Else
					OSType = OSType + " Unknown Edition"
				EndIf
				CloseLibrary(0)
			EndIf
		ElseIf ReadEx = 1 ;GetVersionEx data have been read and the OS is 2000/XP/2003, neither Vista nor 2008,
			If wPT = 1 ;Then 'VER_NT_WORKSTATION
				If (SM & $200) = $200;VER_SUITE_PERSONAL 
					OSType = OSType + " Home"
				Else
					If mv = 5 : OSType = OSType + " Professional":EndIf
					If mv = 4 : OSType = OSType + " Workstation":EndIf
				EndIf
			Else ;ProgType=3 = VER_NT_SERVER
				If (SM & $80) = $80;VER_SUITE_DATACENTER
					OSType = OSType + " DataCenter Server"
				ElseIf (SM & 2) = 2;VER_SUITE_ENTERPRISE
					OSType = OSType + " Enterprise Edition"
				Else
					OSType = OSType + " Server"
				EndIf
			EndIf ;'ProgType
		EndIf
		If mv = 5 And miv = 1
			If GetSystemMetrics_(87) ;Media center
				OSType = "Windows XP Media Center"
				aa.s = Space(255):bb.l = 255
				GetWindowsDirectory_(@aa, @bb)
				tmpos.s = ReplaceString(tmpos, "5.1.2600.", "")
				If Val(tmpos) <= 1200
					OSType = OSType + " 2002"
				ElseIf Val(tmpos) <= 2500
					OSType = OSType + " 2004"
				Else
					OSType = OSType + " 2005"
				EndIf
				If GetSystemMetrics_(86) : OSType = "Windows XP Tablet PC":EndIf
			EndIf
		EndIf
	EndIf
Else ; 4.0 SP5
	Typ.s = GetString(#HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\ProductOptions", "ProductType",2)
	If FindString(UCase(Typ), "WINNT",1) > 0: OSType = "Windows NT Service Pack 5 Workstation": EndIf
	If FindString(UCase(Typ), "LANMANNT",1) > 0: OSType = "Windows NT Service Pack 5 Server": EndIf
	If FindString(UCase(Typ), "SERVERNT",1) > 0: OSType = "Windows NT Service Pack 5 Advanced Server": EndIf
EndIf
;OS capabilities
If SM & 1: OSCapabilities = "SMALL BUSINESS, ": EndIf
If SM & 2: OSCapabilities + "ENTERPRISE, ": EndIf
If SM & 4: OSCapabilities + "BACK OFFICE, ": EndIf
If SM & 8: OSCapabilities + "COMMUNICATIONS, ": EndIf
If SM & $10: OSCapabilities + "TERMINAL, ": EndIf
If SM & $20: OSCapabilities + "SMALL BUSINESS RESTRICTED, ": EndIf
If SM & $40: OSCapabilities + "EMBEDDED NT, ": EndIf
If SM & $80: OSCapabilities + "DATACENTER, ": EndIf
If SM & $100: OSCapabilities + "SINGLE USER, ": EndIf
If SM & $200: OSCapabilities + "PERSONAL, ": EndIf
If SM & $400: OSCapabilities + "BLADE, ": EndIf
If SM & $800: OSCapabilities + "EMBEDDED RESTRICTED, ": EndIf
If SM & $1000: OSCapabilities + "SECURITY APPLIANCE, ": EndIf
If SM & $2000: OSCapabilities + "STORAGE SERVER, ": EndIf
If SM & $4000: OSCapabilities + "COMPUTE SERVER, ": EndIf
If SM & $40000000: OSCapabilities + "WORKSTATION NT, ": EndIf
If SM & $80000000: OSCapabilities + "SERVER NT": EndIf
If Right(OSCapabilities,2) = ", ": OSCapabilities = Left(OSCapabilities,Len(OSCapabilities)-2): EndIf
i = IsWin64()
If i = 1: OSType = OSType + " x64": EndIf
RetOS:
OSType = OSType + " " + Str(mv) + "." + Str(miv) + "." + Str(c & $FFF) + " " + b
ProcedureReturn OSType
EndProcedure

If OpenWindow(0, 100, 200, 450, 60, "Windows' version", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)

If CreateGadgetList(WindowID(0))
TextGadget(0,10,10,60,20, "OS version : ")
TextGadget(1,10,30,60,20, "Capabilities : ")
TextGadget(2,75,10,430,20, OSType())
TextGadget(3,75,30,430,20, OSCapabilities)
EndIf

  Repeat
    EventID = WaitWindowEvent()

    If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf

  Until Quit = 1
  
EndIf

End 

Posted: Thu May 28, 2009 3:11 pm
by Rings
can you provide a version thats works under a actual (4.3) version ?
i can't compile the source without lots of compiler-syntax errors.
thx.

Posted: Thu May 28, 2009 3:49 pm
by dige
pb4.31

Code: Select all

; Author: Wicker Man
; Date: May 22 2009
; OS: Windows
; Demo: No
; More codes at: www.geocities.com/kc2000labs/pb/pb.htm


DataSection
  CLSID_WbemLocator:
  ;4590f811-1d3a-11d0-891f-00aa004b2e24
  Data.l $4590F811
  Data.w $1D3A, $11D0
  Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24
  IID_IWbemLocator:
  ;dc12a687-737f-11cf-884d-00aa004b2e24
  Data.l $DC12A687
  Data.w $737F, $11CF
  Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
  IID_IUnknown:
  ;00000000-0000-0000-C000-000000000046
  Data.l $00000000
  Data.w $0000, $0000
  Data.b $C0, $00, $00, $00, $00, $00, $00, $46
  IID_IWbemRefresher:
  ;49353c99-516b-11d1-aea6-00c04fb68820
  Data.l $49353C99
  Data.w $516B, $11D1
  Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
  CLSID_WbemRefresher:
  ;c71566f2-561E-11D1-AD87-00C04FD8FDFF
  Data.l $C71566F2
  Data.w $561E, $11D1
  Data.b $AD,$87,$00,$C0,$4F,$D8,$FD,$FF
  IID_IWbemConfigureRefresher:
  ;49353c92-516b-11d1-aea6-00c04fb68820
  Data.l $49353C92
  Data.w $516B, $11D1
  Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
  IID_IWbemObjectAccess:
  ;49353c9a-516b-11d1-aea6-00c04fb68820
  Data.l $49353C9A
  Data.w $516B, $11D1
  Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
EndDataSection


#COINIT_MULTITHREAD=0
#RPC_C_AUTHN_LEVEL_CONNECT=2
#RPC_C_IMP_LEVEL_IDENTIFY=2
#EOAC_NONE=0
#RPC_C_AUTHN_WINNT=10
#RPC_C_AUTHZ_NONE=0
#RPC_C_AUTHN_LEVEL_CALL=3
#RPC_C_IMP_LEVEL_IMPERSONATE=3
#CLSCTX_INPROC_SERVER=1
#WBEM_S_NO_ERROR = 0

Global OSCapabilities.s

Procedure.l ansi2bstr(ansi.s)
  size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0)
  Dim unicode.w(size)
  MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size)
  ProcedureReturn SysAllocString_(@unicode())
EndProcedure

Procedure.s unicode2ansi(mem)
  ansi.s=""
  Repeat
    a=PeekW(mem)
    ansi=ansi+Chr(a)
    mem+2
  Until a=0
  ProcedureReturn ansi
EndProcedure

Procedure.l CheckXP();Tell us if the OS is XP or not. Used to separate XP x64 from 2003 x83 as they have the same version number: 5.2.3790
  CoInitializeEx_(0,#COINIT_MULTITHREAD)
  hres=CoInitializeSecurity_(0, -1,0,0,#RPC_C_AUTHN_LEVEL_CONNECT,#RPC_C_IMP_LEVEL_IDENTIFY,0,#EOAC_NONE,0)
  hres=CoCreateInstance_(?CLSID_WbemLocator,0,#CLSCTX_INPROC_SERVER,?IID_IWbemLocator,@loc.IWbemLocator)
  hres=loc\ConnectServer(ansi2bstr("root\cimv2"),0,0,0,0,0,0,@svc.IWbemServices)
  hres=svc\queryinterface(?IID_IUnknown,@pUnk.IUnknown)
  hres=CoSetProxyBlanket_(svc,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE)
  hres=CoSetProxyBlanket_(pUnk,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE)
  pUnk\release()
  hres=CoCreateInstance_(?CLSID_WbemRefresher,0,#CLSCTX_INPROC_SERVER,?IID_IWbemRefresher,@pRefresher.IWbemRefresher)
  hres=pRefresher\queryinterface(?IID_IWbemConfigureRefresher,@pConfig.IWbemConfigureRefresher)
  hres=pConfig\AddEnum(svc,ansi2bstr("Win32_OperatingSystem"),0,0,@penum.IWbemHiPerfEnum,@id)
  pConfig\release()
  Dim tab.IWbemObjectAccess(300)
  pRefresher\refresh(0)
  hres=penum\GetObjects(0,100*SizeOf(IWbemObjectAccess),@tab(),@retour.l)
  hres=tab(0)\GetPropertyHandle(ansi2bstr("Caption"),0,@caption) 
  
  *MemoryID = AllocateMemory(500)
  
  For i=0 To retour-1
    tab(i)\Readpropertyvalue(caption,500,@len,*MemoryID)
    XPstring.s = unicode2ansi(*MemoryID)
    tab(i)\release()
  Next i
  
  FreeMemory(*MemoryID)
  penum\release()
  pRefresher\release();
  svc\release()
  loc\release()
  CoUninitialize_()
  If FindString(XPstring,"XP",1)
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

Procedure.l IsWin64();Tell us if the OS is x64 or not.
  *Is64 = 0
  If OpenLibrary(0,"KERNEL32.DLL")
    *F = GetFunction(0,"IsWow64Process")
    If *F
      CallFunctionFast(*F,GetCurrentProcess_(), @*Is64)
    EndIf
    CloseLibrary(0)
  EndIf
  If *Is64>0
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

Procedure.s GetString(hKey.l, strPath.s, strValue.s, RegType.l=2)
  ;OnErrorResume()
  KeyHand.l:datatype.l:lresult.l
  Dim strBuf.b(1):lDataBufSize.l
  intZeroPos.l:tempV.l:mm.l
  r = RegOpenKey_(hKey, strPath, @KeyHand)
  lresult = RegQueryValueEx_(KeyHand, strValue, 0, @lValueType, 0, @lDataBufSize)
  mm=lDataBufSize
  If lDataBufSize > 0
    Redim strBuf.b(lDataBufSize-1)
  EndIf
  lresult = RegQueryValueEx_(KeyHand, @strValue, 0, @RegType, @strBuf(), @lDataBufSize)
  If lresult = #ERROR_SUCCESS
    If lValueType = 4
      tempV.l = 0
      For i = 0 To lDataBufSize-1;Len(strBuf)
        tempV = tempV + (strBuf(i) & $FF) * Pow(16,(2 * i))
      Next
      ProcedureReturn StrU(tempV,#PB_Long)
    EndIf
    tmp.s
    If RegType = #REG_MULTI_SZ
      For i=0 To lDataBufSize-1
        If strBuf(i)=0
          tmp + " , "
        Else
          tmp+ Chr(strBuf(i))
        EndIf
      Next
      For i=lDataBufSize-1 To 0 Step -1
        If Right(tmp,3)=" , ":tmp = Left(tmp,Len(tmp)-3):EndIf
      Next
      ProcedureReturn tmp + "."
    EndIf
    For i=0 To lDataBufSize-1
      tmp+ Chr(strBuf(i))
    Next
    ProcedureReturn tmp
  EndIf
EndProcedure

Procedure.s OSType()
  Define.l m, mv, c, pd, miv
  OSType.s: b.s
  Global OS.OSVERSIONINFO
  Global os1.OSVERSIONINFOEX
  OS\dwOSVersionInfoSize = SizeOf(OS)    ; 'Assign some size to store the received information
  GetVersionEx_(@OS)
  If OS\dwPlatformId = 2; get some extra data under Windows NT and later
    os1\dwOSVersionInfoSize =SizeOf(os1)    ; 'Assign some size to store the received information
    GetVersionEx_(@os1)
    ReadEx = 1; extra data have been read
    mv = os1\dwMajorVersion
    pd = os1\dwPlatformId
    miv = os1\dwMinorVersion
    b = PeekS(@os1\szCSDVersion)
    c = os1\dwBuildNumber
    d = os1\wServicePackMajor
    E = os1\wServicePackMinor
    wPT = os1\wProductType
    G = os1\wReserved
    SM = os1\wSuiteMask
  Else
    mv = OS\dwMajorVersion
    pd = OS\dwPlatformId
    miv = OS\dwMinorVersion
    b = PeekS(@OS\szCSDVersion)
    c = OS\dwBuildNumber
  EndIf
  If OS\dwMajorVersion <> 0
    Check:
    If pd = 1
      If miv = 0
        OSType = "Windows 95"
        If (c & $FFF) >= 1214
          OSType = OSType + " OSR 2.5": Goto RetOS
        EndIf
        If (c & $FFF) >= 1212
          OSType = OSType + " OSR 2.1": Goto RetOS
        EndIf
        If (c & $FFF) = 1111
          OSType = OSType + " OSR 2": Goto RetOS
        EndIf
      EndIf
      If miv = 10
        OSType = "Windows 98"
        If (c & $FFF) >= 2222
          OSType = OSType + " Second Edition": Goto RetOS
        EndIf
        If (c & $FFF) >= 2000
          OSType = OSType + " SP1": Goto RetOS
        EndIf
      EndIf
      If miv = 90
        OSType = "Windows ME"
      EndIf
    ElseIf pd = 2
      OSType = "Windows NT"
      If mv = 3 : OSType = OSType + " 3." + Str(miv):EndIf
      If mv = 4 : OSType = OSType + " 4.0":EndIf
      If mv = 5
        If miv = 0 : OSType = "Windows 2000":EndIf
        If miv = 1 : OSType = "Windows XP":EndIf
        If miv = 2
          If CheckXP() = 1; this is needed for XP x64 version
            OSType = "Windows XP"
          Else
            OSType = "Windows Server 2003"
          EndIf
        EndIf
      EndIf
      If mv = 6
        If miv = 0
          OSType = "Windows Vista"
        Else
          OSType = "Windows Server 2008"
        EndIf
        If OSVersion() = #PB_OS_Windows_Server_2008 : OSType = "Windows Server 2008":EndIf
      EndIf
      If mv >= 6 ; for Vista, Server 2008 and future versions
        DLLhandle.l: ulProductType.l
        If OpenLibrary(0,"KERNEL32.DLL")
          *F = GetFunction(0,"GetProductInfo")
          If *F
            CallFunctionFast(*F,6,0,0,0,@ulProductType)
            
            Select (ulProductType)
              Case 6;; 'PRODUCT_BUSINESS
                OSType = OSType + " Business Edition"
                
              Case $10;; 'PRODUCT_BUSINESS_N
                OSType = OSType + " BusinessN Edition"
                
              Case $12;; 'PRODUCT_CLUSTER_SERVER
                OSType = OSType + " Cluster Server Edition"
                
              Case $8;; 'PRODUCT_DATACENTER_SERVER
                OSType = OSType + " Datacenter Edition (Full installation)"
                
              Case $C;; 'PRODUCT_DATACENTER_SERVER_CORE
                OSType = OSType + " Datacenter Edition (Server Core installation)"
                
              Case $4;; 'PRODUCT_ENTERPRISE
                OSType = OSType + " Enterprise Edition"
                
              Case $1B;; 'PRODUCT_ENTERPRISE_N
                OSType = OSType + " EnterpriseN Edition"
                
              Case $A;; 'PRODUCT_ENTERPRISE_SERVER
                OSType = OSType + " Enterprise Edition (Full installation)"
                
              Case $E;; 'PRODUCT_ENTERPRISE_SERVER_CORE
                OSType = OSType + " Enterprise Edition (Server Core installation)"
                
              Case $F;; 'PRODUCT_ENTERPRISE_SERVER_IA64
                OSType = OSType + " Datacenter Enterprise Edition for Itanium-based Systems"
                
              Case $2;; 'PRODUCT_HOME_BASIC
                OSType = OSType + " Home Basic Edition"
                
              Case $5;; 'PRODUCT_HOME_BASIC_N
                OSType = OSType + " Home BasicN Edition"
                
              Case $3;; 'PRODUCT_HOME_PREMIUM
                OSType = OSType + " Home Premium Edition"
                
              Case $1A; 'PRODUCT_HOME_PREMIUM_N
                OSType = OSType + " Home PremiumN Edition"
                
              Case $13; 'PRODUCT_HOME_SERVER
                OSType = OSType + " Home Server Edition"
                
              Case $18; 'PRODUCT_SERVER_FOR_SMALLBUSINESS
                OSType = OSType + " Server for Small Business Edition"
                
              Case $9; 'PRODUCT_SMALLBUSINESS_SERVER
                OSType = OSType + " Small Business Server Edition"
                
              Case $19; 'PRODUCT_SMALLBUSINESS_SERVER_PREMIUM
                OSType = OSType + " Small Business Server Premium Edition"
                
              Case $7; 'PRODUCT_STANDARD_SERVER
                OSType = OSType + " Standard Server Edition (Full installation)"
                
              Case $D; 'PRODUCT_STANDARD_SERVER_CORE
                OSType = OSType + " Standard Server Edition (Core installation)"
                
              Case $B; 'PRODUCT_STARTER
                OSType = OSType + " Starter Edition"
                
              Case $17; 'PRODUCT_STORAGE_ENTERPRISE_SERVER
                OSType = OSType + " Storage Server Enterprise Edition"
                
              Case $14; 'PRODUCT_STORAGE_EXPRESS_SERVER
                OSType = OSType + " Storage Express Server Edition"
                
              Case $15; 'PRODUCT_STORAGE_STANDARD_SERVER
                OSType = OSType + " Storage Standard Server Edition"
                
              Case $16; 'PRODUCT_STORAGE_WORKGROUP_SERVER
                OSType = OSType + " Storage Workgroup Server Edition"
                
              Case $1; 'PRODUCT_ULTIMATE
                OSType = OSType + " Ultimate Edition"
                
              Case $1C; 'PRODUCT_ULTIMATE
                OSType = OSType + " Ultimate Edition"
                
              Case $11; 'PRODUCT_WEB_SERVER
                OSType = OSType + " Web Server Edition"
                
              Default
                OSType = OSType + " Unknown Edition (" + Str(ulProductType) + ")"
            EndSelect
          Else
            OSType = OSType + " Unknown Edition"
          EndIf
          CloseLibrary(0)
        EndIf
      ElseIf ReadEx = 1 ;GetVersionEx data have been read and the OS is 2000/XP/2003, neither Vista nor 2008,
        If wPT = 1 ;Then 'VER_NT_WORKSTATION
          If (SM & $200) = $200;VER_SUITE_PERSONAL
            OSType = OSType + " Home"
          Else
            If mv = 5 : OSType = OSType + " Professional":EndIf
            If mv = 4 : OSType = OSType + " Workstation":EndIf
          EndIf
        Else ;ProgType=3 = VER_NT_SERVER
          If (SM & $80) = $80;VER_SUITE_DATACENTER
            OSType = OSType + " DataCenter Server"
          ElseIf (SM & 2) = 2;VER_SUITE_ENTERPRISE
            OSType = OSType + " Enterprise Edition"
          Else
            OSType = OSType + " Server"
          EndIf
        EndIf ;'ProgType
      EndIf
      If mv = 5 And miv = 1
        If GetSystemMetrics_(87) ;Media center
          OSType = "Windows XP Media Center"
          aa.s = Space(255):bb.l = 255
          GetWindowsDirectory_(@aa, @bb)
          tmpos.s = ReplaceString(tmpos, "5.1.2600.", "")
          If Val(tmpos) <= 1200
            OSType = OSType + " 2002"
          ElseIf Val(tmpos) <= 2500
            OSType = OSType + " 2004"
          Else
            OSType = OSType + " 2005"
          EndIf
          If GetSystemMetrics_(86) : OSType = "Windows XP Tablet PC":EndIf
        EndIf
      EndIf
    EndIf
  Else ; 4.0 SP5
    Typ.s = GetString(#HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\ProductOptions", "ProductType",2)
    If FindString(UCase(Typ), "WINNT",1) > 0: OSType = "Windows NT Service Pack 5 Workstation": EndIf
    If FindString(UCase(Typ), "LANMANNT",1) > 0: OSType = "Windows NT Service Pack 5 Server": EndIf
    If FindString(UCase(Typ), "SERVERNT",1) > 0: OSType = "Windows NT Service Pack 5 Advanced Server": EndIf
  EndIf
  ;OS capabilities
  If SM & 1: OSCapabilities = "SMALL BUSINESS, ": EndIf
  If SM & 2: OSCapabilities + "ENTERPRISE, ": EndIf
  If SM & 4: OSCapabilities + "BACK OFFICE, ": EndIf
  If SM & 8: OSCapabilities + "COMMUNICATIONS, ": EndIf
  If SM & $10: OSCapabilities + "TERMINAL, ": EndIf
  If SM & $20: OSCapabilities + "SMALL BUSINESS RESTRICTED, ": EndIf
  If SM & $40: OSCapabilities + "EMBEDDED NT, ": EndIf
  If SM & $80: OSCapabilities + "DATACENTER, ": EndIf
  If SM & $100: OSCapabilities + "SINGLE USER, ": EndIf
  If SM & $200: OSCapabilities + "PERSONAL, ": EndIf
  If SM & $400: OSCapabilities + "BLADE, ": EndIf
  If SM & $800: OSCapabilities + "EMBEDDED RESTRICTED, ": EndIf
  If SM & $1000: OSCapabilities + "SECURITY APPLIANCE, ": EndIf
  If SM & $2000: OSCapabilities + "STORAGE SERVER, ": EndIf
  If SM & $4000: OSCapabilities + "COMPUTE SERVER, ": EndIf
  If SM & $40000000: OSCapabilities + "WORKSTATION NT, ": EndIf
  If SM & $80000000: OSCapabilities + "SERVER NT": EndIf
  If Right(OSCapabilities,2) = ", ": OSCapabilities = Left(OSCapabilities,Len(OSCapabilities)-2): EndIf
  i = IsWin64()
  If i = 1: OSType = OSType + " x64": EndIf
  RetOS:
  OSType = OSType + " " + Str(mv) + "." + Str(miv) + "." + Str(c & $FFF) + " " + b
  ProcedureReturn OSType
EndProcedure

If OpenWindow(0, 100, 200, 450, 60, "Windows' version", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
  
  If CreateGadgetList(WindowID(0))
    TextGadget(0,10,10,60,20, "OS version : ")
    TextGadget(1,10,30,60,20, "Capabilities : ")
    TextGadget(2,75,10,430,20, OSType())
    TextGadget(3,75,30,430,20, OSCapabilities)
  EndIf
  
  Repeat
    EventID = WaitWindowEvent()
    
    If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf
    
  Until Quit = 1
  
EndIf

End