[HARBOUR] how can i determine if the computer has win 11 installed

165 views
Skip to first unread message

hherrera

unread,
Sep 13, 2022, 1:04:10 PM9/13/22
to Harbour Users
Hi friends
Could someone tell me if there is a function for harbor, tell me how to know if the computer has win 11 installed.

Thanks

Henry Herrera

Bernard Mouille

unread,
Sep 14, 2022, 2:51:36 AM9/14/22
to Harbour Users
Hello Henry,
Maybe you can take some idea in the code below my signature.
Regards,
Bernard.

// Begin code.

// Test.prg
// Test du module bh_WindowsVersion.ch.

procedure Main

   // ANSI ( Windows ) en français.
   request HB_LANG_FR
   request HB_CODEPAGE_FRWIN
   hb_cdpSelect( 'FRWIN' )
   hb_langSelect( 'FR' )

   // Taille de la console.
   setmode( 25, 80 )
   setcolor( "GR+/B" )
   @ 0, 0, maxrow(), maxcol() box space( 9 )

   ? bh_WindowsVersion()

   ?
   wait
   return

// Renvoie la version de Windows.
function bh_WindowsVersion()

   local oLocator       // Objet WbemScripting.SWbemLocator.
   local oWMI           // Objet ConnectServer.
   local oItem          // Objet processeur.
   local aSys           // Tableau des processeurs : 1 normalement.
   local cReturn := ""  // Valeur retournée par la fonction.

   oLocator := win_OleCreateObject( "WbemScripting.SWbemLocator" )
   oWMI     := oLocator:ConnectServer( ".", "root\cimv2" )
   aSys     := oWMI:ExecQuery( 'Select * from Win32_OperatingSystem' )

   for each oItem in aSys // Il n'y en a qu'1 normalement.
      cReturn += oItem:Caption + " "
      cReturn += oItem:OSArchitecture // pas en XP.
      cReturn += " build " + oItem:BuildNumber
   endfor

   // Libère la mémoire.
   oItem    := nil
   aSys     := nil
   oWMI     := nil
   oLocator := nil

   return strtran( cReturn, space( 2 ), space( 1 ) )
// End code.

hherrera

unread,
Sep 14, 2022, 1:57:38 PM9/14/22
to Harbour Users
Thanks for you answer Bernard!

I've already tried the code you sent me and with a little modification I'm done!

Best Regards,
Henry Herrera

Auge & Ohr

unread,
Sep 14, 2022, 4:08:43 PM9/14/22
to Harbour Users
hi,

WMI will give you BuildNumber e.g. 19044 but not Version like 2006
Microsoft Windows [Version 10.0.19044.2006]

---

try Registry
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentBuild"
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UBR"
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DisplayVersion"

Windows 10 Pro
19044
2006
21H2

Jimmy

Yakano

unread,
Sep 15, 2022, 3:38:18 AM9/15/22
to Harbour Users
Hi, Jimmy

In my Windows 11 Pro,  in the registry...
"\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName" is "Windows 10 Pro", but i have updated to Window 11 Pro (Micro$osft fails?)

So, my question is: better pay attention to...
"\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DisplayVersion" and use "21H2" ???

Regards

Auge & Ohr

unread,
Sep 15, 2022, 3:56:03 AM9/15/22
to Harbour Users
hi,

you are right that it show "windows 10 Pro" instead of "Windows 11 Pro"

but you got Build "CurrentBuild" which is 19xxx for Windows 10 and 22xxx for Windows 11 (DEV have 25xxx)
and "UBR" is need to know which Update are active which change every Month while "xxH1" or "xxH2" is only 1/2 Year

Jimmy

Yakano

unread,
Sep 15, 2022, 4:34:41 AM9/15/22
to Harbour Users
Hi

Yes "CurrentBuild" and "CurrentBuildNumber", both show "22000"

Thanks!

Reply all
Reply to author
Forward
0 new messages