My application needs to determine whether it is running on Windows PE.
Neither the deprecated GetVersionEx function nor the preferred alternative Version Helper APIs offer any indication whether I am operating on WinPE, only indicating the version of the OS.
This reference lists the compatible APIs for WinPE, so I need to be able limit my app to those APIs.
How can I programmatically determine from my App whether I am on WinPE, and which PE version is running?
If you simply need to determine whether you are running WinPE or not, you can check for the presence of the key MiniNT in HKLM\System\CurrentControlSet\Control or HKLM\System\ControlSet001\Control. If it is present, you are on WinPE 2.x or higher.
Cited in MSDN docs here, you can see which version of Windows PE youare running at the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinPE. That reference also gives a table of features and functionality each version will provide you.
For very old versions of Windows/WinPE before 2.0, check the version of %SYSTEMROOT%\SYSTEM32\FACTORY.EXE.
Related
I want to support older Windows versions, but non updated 7 and pre 7 operating systems do not support sha256 code signing, so they cannot detect that the executable/file is properly digitally signed.
My questions are:
How can i check if a system has this update (KB4474419) installed, or basically check if it supports sha256, without causing false positives (for example detecting new windows 10 machines as not having the update by mistake)
How to install this update in the background, without user knowing, and check if installation was successful (in order to see if we should restart the machine or not, in case it was successful) ?
(I want to implement it using c/c++, so native windows APIs are available to solve this)
WUA defines interfaces and objects that are accessible from Visual Basic, Visual Basic Scripting Edition (VBScript), JScript, and from C and C++.
I suggest you could try to use wuapi.h header. This header is used by Windows Update Agent API. And there are some COM interfaces that can be used from C++.
I'd like to use some functions that are only available in Windows 7 or higher in my application but I also want my app to remain compatible with Windows XP. The app should check at runtime if at least Windows 7 is available and offer some advanced features (like Media Foundation support) in that case.
Is the only way to do this to manually check for Windows 7-only DLLs using LoadLibrary and then importing all the functions I need using GetProcAddress()? This would be very inconvenient but I don't see any other way. Statically linking against Windows 7+ DLLs will cause the application to refuse to start on XP because of missing DLLs so this won't work. But doesn't the Windows SDK offer some more convenient technique for programmers who want to remain compatible with older Windows versions and optionally use features of newer Windows versions?
Note that my application is written in plain C so I'm looking for a solution in C.
Don't ever check for OS versions. Check for available features instead.
The most convenient way to keep your code compatible with earlier versions of Windows while still allowing it to opt-in to newer features is to use delay-loading of modules (see Linker Support for Delay-Loaded DLLs). This allows you to benefit from import resolution as you would with compile-time dynamic linking, yet allows you to respond to import failures at runtime.
There are 2 options:
LoadLibrary / GetProcAddress. It is not so inconvenient - you can define and assign function pointers and use them like normal functions.
Compile 2 versions for XP and 7. The installer chooses the right executable or XP version is started by default and it runs second executable if OS is Win7.
Environment:
Visual Studio 2015/Visual C++
OS: Windows 10 TH2 10586 / Corresponding Windows SDK
Since GetVersionEx is deprecated in Windows 8 and later, I wanted to use version helper APIs (IsWindows10OrGreater) to detect the OS in my DLL to decide the flow. However, as per the MSDN documentation, I will need to have a manifest (with compatibility section for supported OS versions) without which this API (IsWindows10OrGreater) will return false even if running in Windows 10.
I have added a manifest with the required compatibility sections but I could not still get it to work. It always returns false. (I have defined manifest ID as 2 in my resource.h as it is DLL)
To cross check, I implemented a sample standalone application with same manifest which works perfectly for this version helper API.
I need your help to understand what am I missing here in the DLL? Unfortunately, none of the discussions available online talk about DLL manifests for compatibility.
Thanks,
The answer comes a bit late, but I had a similar problem, see my question here.
The problem is that the compatibility section of a manifest is ignored when applied to a DLL, it only works when applied to an EXE.
So if you don't control the EXE that will use your DLL and can't be sure that it has the correct manifest, the way to get around it is to get the ProductVersion from the kernel32.dll file. This neatly corresponds with the Windows version and seems pretty reliable (it is also recommended on MSDN).
I have a program that reports and/or detects the Windows OS version. It uses GetVersionEx, but Microsoft intentionally broke this API in Windows 8.1 and later to return incorrect version information. (Apparently proper version checking is just too hard for the masses to get right, but that's a rant for another topic.)
I know that I can add a manifest to work around this particular problem, but my question is about "future-proofing" the program.
If a future user runs the program on a newer OS than Windows 10, will GetVersionEx work correctly and report the "real" OS version, even if the program's manifest doesn't include that version's GUID?
Or am I doomed to continually add new GUIDs to the manifest every time a new OS version is released?
If a future user runs the program on a newer OS than Windows 10, will GetVersionEx work correctly and report the "real" OS version, even if the program's manifest doesn't include that version's GUID?
NO, and this is documented behavior:
With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested.
Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases. To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.
Or am I doomed to continually add new GUIDs to the manifest every time a new OS version is released?
Sadly, YES. The point of version manifestation is to explicitly report the OS version(s) that your app is known to be compatible with. Obviously you can't know ahead of time if it is compatible with future versions. So, whenever a new version is released, you test your app as needed, verify it working (and fix it if needed), and then update the manifest accordingly. Until then, Windows will down-grade itself to behave like the highest OS version that you have reported in your manifest.
You should not be relying on GetVersionEx() to control your app's functionality at runtime anyway. It is fine for reporting the OS version in logs and such (and there are other ways to get the true OS version regardless of manifestation), but don't make decisions based on OS version. For instance, if want to use a given feature that is only available in recent OS versions, don't check the OS version, check for the existence of the feature itself and use it if it is available.
I have Windows 2003 server, with executable built on VC6. I would be needing to check the compatibility of the executable on Windows 2008 server (both servers 32 bit). I know that I need to check for ABI compatibility for these two versions.
How do I confirm that there is ABI compatibility for any two versions of a OS? Or does Windows release the ABI compatibility as part of product document?
Is there any other set of consideration to be taken care apart from ABI compatibility?
Windows maintains binary ABI compatibility between different versions. This means that programs do not need to be re-compiled for different versions.
However, this is not enough to guarantee that a program will run correctly on a version that you have not yet tested. Some examples of possible problems:
You use a deprecated API that has been removed in a later version.
You use an API that exists only on a later version of the OS and so your program fails to run on an older version.
The OS changes functionality that breaks your app. The classic example of this was UAC in Vista. The ABI did not change, but some pre-UAC apps failed to run correctly under UAC.
The bottom line is that you do need to understand the theory behind binary compatibility. But that does not absolve you of the need to test. Make sure that you've tested your program on all supported systems. Or at least as many as you can reasonably manage to find.
See detailed analysis of changes in the Windows API on this page. The reports are generated with the help of the abi-compliance-checker tool.