-
Notifications
You must be signed in to change notification settings - Fork 585
WIP: Improve Windows (Server) version detection #7743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
4e16e5b
to
ff135b6
Compare
This PR is needed to improve the output in #7819. |
This is required as otherwise IsWindows10OrGreater() still returns false. https://docs.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1
So we need an app.manifest which is compiled into the final icinga2.exe. I'm playing around with that. |
So if I understand correctly, Icinga at the moment displays some imprecise version on any recent version of Windows? If so, I think it might be worth looking into this. But I can't believe that there's no way to just get some version string in Windows that we could use. |
Any news here? |
Not from my side. Wanted to have a look at it but you know, there's always something more important to do. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This BREAKS CMake < v3.4 on Windows. At least this works at all.
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Michael Friedrich.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better!
PS C:\Users\aklimov\icinga2> C:\Users\aklimov\icinga2\build\Bin\Release\Debug\icinga2.exe --version
(...)
System information:
Platform: Windows
Platform version: 10 or greater
Kernel: Windows
Kernel version: 10.0
(...)
Is there a list of potentially breaking changes between these versions? They probably don't emulate the old version just for the purpose of making it harder for you to figure out the version you're actually running on. |
Good question. Very good question. |
CC @LordHepipud |
Shouldn't this basically just be a question of compiles/runs yes/no? |
At least it works for me. |
Packages is working on Windows 2012 R2. Output is also correct now:
|
Answering my own question:
I haven't looked through this in detail, but there seems to be nothing that will obviously be a problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also a commit in this PR where the commit message is just "WIP".
lib/base/utility.cpp
Outdated
*platformVersion = "Server 2008 (EOL)"; | ||
} | ||
|
||
} else { | ||
if (IsWindows10OrGreater()) | ||
*platformVersion = "10 or greater"; | ||
else if (IsWindows8Point1OrGreater()) | ||
*platformVersion = "8.1"; | ||
else if (IsWindows8OrGreater()) | ||
*platformVersion = "8"; | ||
else if (IsWindows7SP1OrGreater()) | ||
*platformVersion = "7 SP1 (EOL)"; | ||
else if (IsWindows7OrGreater()) | ||
*platformVersion = "7 (EOL)"; | ||
else | ||
*platformVersion = "Vista (EOL)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not put any EOL information in here. It's just a maintenance burden. It already seems to be outdated.
icinga-app/app.manifest
Outdated
@@ -0,0 +1,19 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MyApplication.app
looks like a placeholder. Shouldn't this be replaced with something more meaningful?
It indeed was work in progress and now I've finished it. |
// https://stackoverflow.com/questions/53393150/c-how-to-detect-windows-server-2019 | ||
// https://techthoughts.info/windows-version-numbers/ | ||
if (IsWindowsServer()) { | ||
// 2019 Server + | ||
if (IsWindowsVersionOrGreater(10, 0, 1803)) { | ||
*platformVersion = "Server 2019 or greater"; | ||
// 2016 Server | ||
} else if (IsWindowsVersionOrGreater(10, 0, 1607)) { | ||
*platformVersion = "Server 2016"; | ||
// 2012 R2 | ||
} else if (IsWindowsVersionOrGreater(6, 3, 0)) { | ||
*platformVersion = "Server 2012 R2"; | ||
// 2012 | ||
} else if (IsWindowsVersionOrGreater(6, 2, 0)) { | ||
*platformVersion = "Server 2012"; | ||
} else { | ||
*platformVersion = "Server 2008"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What versions besides 2012 R2 was this tested on? According to the documentation of IsWindowsVersionOrGreater
, the third parameter is named wServicePackMajor
and to me it's unclear if that would refer to the version number like 1607 or a build number like 14393 or something completely different like 2 as in SP2.
So this should be tested on two 10.0 version, i.e. 2016 and 2019 to ensure that this parameter isn't totally wrong.
if (IsWindowsVersionOrGreater(10, 0, 1803)) { | ||
*platformVersion = "Server 2019 or greater"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source given in the comment right above lists 1803 twice, for both a 2016 and a 2019 version. On the other hand, Wikipedia lists 1809 as the first 2019 version.
According to the Microsoft documentation, the check functions for desktop versions can be used in conjunction with IsWindowsServer()
:
For example, a call to IsWindowsXPSP3OrGreater will return true on Windows Server 2008. Applications that need to distinguish between server and client versions of Windows should call IsWindowsServer.
Would this be good enough for detecting the server release on the granularity we need? Or is there a version that we couldn't distinguish that way? Would at least save us from dealing with the magic numbers involved in this super-intuitive versioning scheme.
@@ -0,0 +1,19 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |||
<assemblyIdentity version="1.0.0.0" name="Icinga 2"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation for name
:
Uniquely names the application or assembly. Use the following format for the name: Organization.Division.Name. For example Microsoft.Windows.mysampleApp. Required.
So doesn't look like a name for human consumption but rather like a scoped identifier. Also not sure if you're supposed to use spaces in there. There's also an example with a 2 level name, so my suggestion for the value would be Icinga.Icinga2
.
Rationale: I was looking into additional Windows environment specifics and thought it would be a good idea to evaluate this again. With the recent VS compiler update, we can also detected Windows 10 (yay), available since the VS2015 SDK.
Detecting the servers is actually fun with the build numbers, especially to distinguish between Server 2016 and 2019.
If this PR works out, @widhalmt should be even happier.
Resources