-8

Simple question : how to detect Windows version in a reliable way using Delphi 2007 ? Is there a way to do it without APIs ie, checking only some folder or files in system directory ?

Thanks in advance !

delphirules
  • 6,443
  • 17
  • 59
  • 108
  • Did you check all the previous 2000 posts when searching with *[delphi] windows version* ? Just of curiosity, why do you avoid API? – Tom Brunberg Mar 02 '17 at 18:16
  • 3
    Because he wants to increase the likelyhood of his code breaking in future version of Windows. You know... Job security! – Ken Bourassa Mar 02 '17 at 18:20
  • @TomBrunberg Yes, but most of them rely on APIs, this is what i'm trying to avoid. – delphirules Mar 02 '17 at 18:22
  • 4
    This is a silly question, you cannot check if a file exists without calling a Windows API function. – Anders Mar 02 '17 at 18:28
  • @Anders Maybe there is some specific file (or files) that only exist in specific versions , that's what i thought. – delphirules Mar 02 '17 at 18:47
  • @delphirules Again, you cannot check if a file exists without calling a API! Even if you could, it is risky because some people will copy over a .dll from another system etc. Can you explain why you need to avoid calling any API functions? – Anders Mar 02 '17 at 18:51
  • @Anders Actually i'm trying to avoid any problem with permissions and / or anti-virus issues. Some AV checks calling of APIs to flag the app. – delphirules Mar 02 '17 at 19:00
  • 3
    @delphirules I have never heard of AV flagging something because they call GetVersionEx etc. If your app is getting flagged it must be something else. – Anders Mar 02 '17 at 19:04
  • 1
    *some AV checks* Nonsense. They may check calling of **specific API functions** that might be commonly used by malware, but every single application running on Windows uses API calls (CreateWindow() for a GUI app, even Delphi ones, and the console-related functions for console apps). You cannot run an app on Windows without an API call, and if you think you can you should consider another hobby or career. – Ken White Mar 08 '17 at 13:54

2 Answers2

8

You cannot check a file or registry value without calling a Windows API function!

The only way to check the version without calling any API is to read from the PEB but most of the fields there are undocumented and could in theory change from version to version. It is also affected by the compatibility shims. I don't recommend that you do this but if you insist then this code might be a good starting point, just read the OSMajorVersion and OSMinorVersion members (Teb from GetTeb and Peb := Teb.Peb from Teb).

Microsoft recommends that you check if the feature you need exists instead of checking the version. The recommended way to check the version is with VerifyVersionInfo but you can still continue to use the deprecated GetVersionEx if you need the version number for display purposes. Both of these functions require a manifest to get the correct version on Windows 8.1 and 10.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • On Windows 10, VerifyVersionInfo() is subject to manifestation, same as GetVersionEx() in Win8.1 onward. There are several other API functions available to get the true OS version number without manifestation. – Remy Lebeau Mar 03 '17 at 08:22
  • [This Q&A](http://stackoverflow.com/q/36543301/1889329) explains, how to detect the true OS version in absence of any manifests. – IInspectable Mar 03 '17 at 11:12
  • @IInspectable it is not the true version, it is still affected by compatibility shims. – Anders Mar 03 '17 at 16:46
0

In theory you can parse EXPLORER.EXE for its version details and then speculate on the Windows version. But every Delphi version uses for Pascal's blockread() implementation the WinApi again. And wanting tofind the Windows-directory (which can have any name on any drive) also leads to WinApi calls again.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31