Thread: Operating System Detection APIs.

  1. #1
    Registered User
    Join Date
    Jul 2015
    Posts
    64

    Question Operating System Detection APIs.

    Good evening Cboard!

    So, this is a pretty basic question, but it has been frustrating me for a while now. I am trying to programatically determine which Windows OS my program is running on. I am already aware of various APIs that are designed to achieve this, namely the GetVersion() and GetVersionEx() functions, along with their successor Version Helper functions defined in <versionhelpers.h>.

    My issue with the former two functions is that they seem to 'chop and change' from OS to OS and I'm looking to make my code as "Windows-portable" as possible (ideally even extending back to the Windows 95 era). For instance, MSDN states that "Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2)". This sort of inconsistency is hopefully avoidable; I am really disappointed in Microsoft for no longer abiding by their prior backwards-compatibility ethos.

    That leads me on to the Version Helper functions. Unfortunately, programming is only a hobby of mine and, as such, I am reluctant to spend money on the go-to professional IDE, Visual Studio. I am aware that a free Express version exists, however, a few reviews of the software claim that it is an absolute nightmare to work with a "crippled" (i.e. restricted,) IDE. At the moment, I am working with the latest version of CodeBlocks, which ships with outdated Windows headers, ruling out the use of Version Helper functions. (There is, of course, the Windows SDK, but having installed it in the past, it seems that CodeBlocks just doesn't like it. A lot of errors are thrown from just including Windows.h from the SDK. Also, I'm not going to lie; I've even considered using a cracked version of Visual Studio to get the job done, but I try very hard to avoid pirated software unless ABSOLUTELY necessary.)

    So I guess my questions is: "Any ideas?". Maybe it would be feasible to code my own OS fingerprinting function/library by perhaps scanning the filesystem and registry for entries that are unique to each individual version of Windows. This would, however, be very difficult as I only really have access to Windows Vista/7/8 machines; I'm unsure of how I can discover unique "artefacts" with which I can identify the other operating systems. Short of putting significant effort into creating such a codebase and re-inventing the wheel, I'm at a loss as to what I can do.

    Any suggestions would be hugely appreciated!

    Many thanks,
    Abyssion
    Last edited by Abyssion; 10-27-2015 at 04:25 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The community edition is a full featured FREE edition. That might give you somewhere to start.
    But I'll also note that for newer versions of Windows, you SHOULD be including a manifest. So if your program is without one, it technically won't be a software written for "newer" versions of Windows.

    Also, you know the W10 upgrade is free, yes (for now, anyway)? You can put a windows into a VM and upgrade that to get a W10 copy to play around with.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2015
    Posts
    64
    Many thanks for your reply, Elysia!
    I apologise for the slight bump; I've barely had a moment to myself for the past week or so to reply.

    Anyway, after a quick trip to the casino for a friend's stag do, I found myself with enough funds to purchase and set up the professional version of Visual Studio 2015 It's taking some getting used to, but I'm getting there slowly. The thing that's taking the most getting used to is the IDE's effect on the (Windows 7) filesystem. Whereas the CodeBlocks installation simply created a folder in Program files and one in Program Data (and perhaps some %APPDATA% files), Visual Studio, with all of it's various components, seems to be all over the show. (I made the mistake of installing most of the components available: "F#? Yeah, I might need that some day...")

    Anyway, I've been looking for resources online about the installation paths that the IDE takes, but have come up short thus far. I can't for instance find the windows.h header anywhere in my filesystem (even Explorer's search function could not find it), however, I can still include it in my projects without non-definition errors, so it's definately hiding somewhere. I've had a look through the IDE's options interface already, so I am not holding out much hope for this, but I was wondering if there is any way to customize all of the paths that the IDE defaults to so I can make Visual Studio's filesystem footprint more "compact" and easy to navigate? Also, it keeps creating a "Visual Studio 2015" folder in My Documents upon startup, which is really annoying; is there any way to stop this? I have already relocated my projects and templates in the filesystem and changed VS' default directories for these, but it still wants to make folders each time it starts.

    Also, just a quick question about the virtual machine idea, if you don't mind. (Thank you for the suggestion!) My understanding of virtual machines is that one needs to actually own the operating system that they wish to install on it - is this correct? Or do VM applications ship with a selection of operating systems already prepared (perhaps as .iso files)? Due to copyright laws, I would assume that the former is the case. Does anyone have any personal preferences when it comes to machine virtualisation software? It seems to me that VMware is the most common tool available these days, but perhaps someone with more experience in the field might recommend something different.

    Many thanks for your time, and apologies about the length of this post.

    Abyssion

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Abyssion View Post
    Anyway, after a quick trip to the casino for a friend's stag do, I found myself with enough funds to purchase and set up the professional version of Visual Studio 2015
    Why? Why would you pay for something that's free for everyone but big corporations? Why?

    Anyway, I've been looking for resources online about the installation paths that the IDE takes, but have come up short thus far. I can't for instance find the windows.h header anywhere in my filesystem (even Explorer's search function could not find it), however, I can still include it in my projects without non-definition errors, so it's definately hiding somewhere.
    It should be in C:\Program Files (x86)\Windows Kits\8.1\Include\um (thanks, Everything--and btw, install that instead of the Explorer junk search - finds anything in less than a second).

    I've had a look through the IDE's options interface already, so I am not holding out much hope for this, but I was wondering if there is any way to customize all of the paths that the IDE defaults to so I can make Visual Studio's filesystem footprint more "compact" and easy to navigate?
    I don't think so, unfortunately. The IDE has a lot of "dependencies" which goes into their own folders.

    Also, it keeps creating a "Visual Studio 2015" folder in My Documents upon startup, which is really annoying; is there any way to stop this? I have already relocated my projects and templates in the filesystem and changed VS' default directories for these, but it still wants to make folders each time it starts.
    Can't say I have any experience with that. I just let that folder it creates lie there, even though I have my projects at another location.

    Also, just a quick question about the virtual machine idea, if you don't mind. (Thank you for the suggestion!) My understanding of virtual machines is that one needs to actually own the operating system that they wish to install on it - is this correct?
    Yes, you need a license for the OS you wish to install.
    (Unless we're talking about free Linux distros.)

    Does anyone have any personal preferences when it comes to machine virtualisation software? It seems to me that VMware is the most common tool available these days, but perhaps someone with more experience in the field might recommend something different.
    VMWare (Player) and VirtualBox are good ones. Personally, I go with VMWare Player mostly because it just works for me and I haven't had any needs that it couldn't fulfill so far. I had trouble with VirtualBox some years back (it was so slow!), but not with VMWare.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jul 2015
    Posts
    64
    Why? Why would you pay for something that's free for everyone but big corporations?
    Maybe I have made a big mistake by doing so. However, whilst your first reply pointed me in the direction of the community edition, I checked Microsoft's "compare editions" page, and there were a few "ticks" missing from the community edition that were present for Pro. Having installed it and fiddled with it now, I realise that most of these features aren't likely to be used by myself any time soon, but I feel it's good to have them available should the need arise.

    It should be in C:\Program Files (x86)\Windows Kits\8.1\Include\um (thanks, Everything--and btw, install that instead of the Explorer junk search - finds anything in less than a second).
    Wonderful, found it; thank you! Am I right in thinking these are the headers that would ship with the latest SDK (i.e. up-to-date headers)? And Everything looks awesome, I shall indeed install it; cheers for the pointer.

    Shame about VS' dependencies and filesystem usage. I shall look into VMware Player and try to dig out my old Operating system disks. Pretty sure I've got Vista, XP and 98 lying around the house somewhere.

    Do you (or does anyone else) happened to know of a resource from which I can learn about the structure of Visual Studio's project folders? Again, I'm comparing CodeBlocks and oranges here, but with my old IDE, I simply had a project file, source files and object files, a .layout file and a .depend file. Plus one or two folders (for different configurations,) for the actual executables. Visual Studio, on the other hand, generates a much more complex directory structure. I shall have a look on msdn at the different filetypes, but alot of it seems pretty redundant.

    Also, pertaining to the inclusion of header files, does Visual Studio have a hardcoded list of include directories? I seem able to include windows.h alongside standard library headers without ever having to specify a fully qualified path to the files. A hardcoded list is the only way I can think of that this could be achieved.

    Many thanks for your help Elysia!

    Abyssion
    Last edited by Abyssion; 11-11-2015 at 03:25 PM. Reason: Grammar

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Abyssion View Post
    Wonderful, found it; thank you! Am I right in thinking these are the headers that would ship with the latest SDK (i.e. up-to-date headers)? And Everything looks awesome, I shall indeed install it; cheers for the pointer.
    The latest IDE ships with the latest platform SDK headers, as far as I know.

    Does you (or anyone else) happened to know of a resource from which I can learn about the structure of Visual Studio's project folders? Again, I'm comparing CodeBlocks and oranges here, but with my old IDE, I simply had a project file, source files and object files, a .layout file and a .depend file. Plus one or two folders (for different configurations,) for the actual executables. Visual Studio, on the other hand, generates a much more complex directory structure. I shall have a look on msdn at the different filetypes, but alot of it seems pretty redundant.
    I can probably mention a few things...

    .apk file - No idea
    .sln file - Contains your solution, which contains information about the paths to your projects, among other things
    .vcxproj - Your project
    .vcxproj.filters - Contains the filter structure of your projects/solutions, I believe.
    .vcxproj.user - Contains various configuration stuff for your projects
    .suo - Contains stuff specific to your solution/projects such as IDE layout
    Debug/Release folder - Contains all the compiled files and executables for your project
    x64 folder - Contains Debug/Release folders for targeting x64 instead of x86
    .exp - Information about exported functions from DLL files, I believe
    .ilk - Used for incremental linking
    .pdb - Used for debugging symbols for your executables
    .sdf - Database containing intellisense information for your project
    .ipch - Precompiled header
    .obj - Compiled intermediate file (i.e. object file) used for linking
    .pch - Precompiled header

    Also, pertaining to the inclusion of header files, does Visual Studio have a hardcoded list of include directories? I seem able to include windows.h alongside standard library headers without ever having to specify a fully qualified path to the files. A hardcoded list is the only way I can think of that this could be achieved.
    It doesn't have hard-coded paths, per se. They are certainly pre-configured, but you can change them. Use the property manager to access the default "built-in" property sheets. I don't recall off-hand exactly what they're named, though. But in them, you can find VC++ Directories, where you can add all sorts of paths. Maybe google add visual c++ paths?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Jul 2015
    Posts
    64
    The latest IDE ships with the latest platform SDK headers, as far as I know.
    I believe so too, cheers for the clarification.

    That list of file types is extremely helpful Elysia, thank you very much! I've actually copied and pasted that information into a text file on my machine for future reference; I hope you don't mind?

    Cheers for pointing me in the direction of the property manager for default include path configurations. I was thinking more along the lines of whacking the Windows Kits folder (amongst other SDKish type things,) actually inside the Visual Studio installation folder, in a subfolder called SDKs or something. Just to clear up a bit of the installation-mess that VS created on my filesystem. Of course, anything that is not configurable from within the IDE itself, I shall leave be. Would this be a really bad idea, or do you think it could work?

    Cheers,
    Abyssion

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Abyssion View Post
    That list of file types is extremely helpful Elysia, thank you very much! I've actually copied and pasted that information into a text file on my machine for future reference; I hope you don't mind?
    No probs.

    Cheers for pointing me in the direction of the property manager for default include path configurations. I was thinking more along the lines of whacking the Windows Kits folder (amongst other SDKish type things,) actually inside the Visual Studio installation folder, in a subfolder called SDKs or something. Just to clear up a bit of the installation-mess that VS created on my filesystem. Of course, anything that is not configurable from within the IDE itself, I shall leave be. Would this be a really bad idea, or do you think it could work?
    I honestly wouldn't really care about it. You could probably with some research figure out how to change it and make it work, but I mean, why put down the time to do that when it can be better spent on other things?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jul 2015
    Posts
    64
    I honestly wouldn't really care about it. You could probably with some research figure out how to change it and make it work, but I mean, why put down the time to do that when it can be better spent on other things?
    Yeah, I guess you're right. I might just mark them as operating system directories to hide them from the part of my mind that is obsessively well-organised!

    Thank you for all your advice, I understand so much more now!
    Have a great day,

    Abyssion

  10. #10
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Abyssion View Post
    ideally even extending back to the Windows 95 era
    Interesting, you going to distribute your program as a 16-bit executable? While you're at it, be sure to provide a DOS version too.


    Quote Originally Posted by Abyssion View Post
    So I guess my questions is: "Any ideas?". Maybe it would be feasible to code my own OS fingerprinting function/library by perhaps scanning the filesystem and registry for entries that are unique to each individual version of Windows.
    Don't bother with detecting the OS's version. It's usually wasted effort, just test for what ever feature you want to use. Rather than telling your user "Ur windoze is 2 old", you can tell them "X-Feature is unavailable".

  11. #11
    Registered User
    Join Date
    Jul 2015
    Posts
    64
    Interesting, you going to distribute your program as a 16-bit executable? While you're at it, be sure to provide a DOS version too.
    Well, numerous sources that I have read hint at Windows 95 being able to support 32-bit applications. However, assuming that my program fails to run on a 95 virtual machine, then yes - that's exactly what I intend to do. I have the tools for the job available to me already, so why not?

  12. #12
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    Windows 95/98 was something of a hybrid 16/32 bit OS. Yes, I did piles of 32 bit Win95 coding.

    Kind of related to your questions, sometime back I had to make a setup program for some of my exes. We have both 32 bit and 64 bit Win7 OSs whetre I work. What seemed to work for me was searching the environment table for the string...

    "Program Files (x86)"

    If I found that I knew I had a 64 bit Win7 machine. However, I was using another programming language that had a command that dumped the environment table. I'd have to look it up to see how to do that in C/C++.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by freddie View Post
    What seemed to work for me was searching the environment table for the string...

    "Program Files (x86)"

    If I found that I knew I had a 64 bit Win7 machine.
    An extremely poor solutions. First off, it really only works on English machines, and you know that's just a minority of the world.
    Secondly, the user can change this directory. This foils this plan altogether.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Jul 2015
    Posts
    64
    Cheers for the info Freddie! This was definately the sort of "artefact" I was referring to. The plan, as inspired by Elysia, was initially to create virtual machines and install various Windows operating systems on them to identify unique filesystem or registry entries. This does seem to entail an awful lot of work though, especially for a codebase that has already been created and, as Elysia pointed out, such items do not necessarily guarantee uniqueness from OS to OS.

    Surely there must be be some kind of marker built into the Operating System? If one were to right-click on computer on the start menu and select properties, the "System" control panel process that is launched can fingerprint the operating system (apparently) easily. The same can be said about programs such as Piriform's Speccy. (Fantastic program btw, highly recommended.) I may run Speccy whilst monitoring it's API calls to see which functions are utilised. However, this is only really out of curiosity now; I have access to an up-to-date IDE, so hopefully the Version Helper functions will be a great help.

    Cheers guys!

  15. #15
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    Elysia said...

    An extremely poor solutions. First off, it really only works on English machines, and you know that's just a minority of the world.
    Secondly, the user can change this directory. This foils this plan altogether.
    I thought so too. But it was the best I could come up with having sunk only about a half hour into the endeavor. All my programs are only used in the state of Pennsylvania in the United States in state goverment office buildings. And English is still marginally the predominent language there. So it works. Sometimes 'good enough' really is good enough.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Operating System
    By Houssen in forum C Programming
    Replies: 18
    Last Post: 04-22-2008, 12:51 PM
  2. Any good windows system APIs?
    By taelmx in forum Windows Programming
    Replies: 2
    Last Post: 11-08-2006, 12:43 AM
  3. What is your operating system?
    By undisputed007 in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 04-17-2004, 02:56 PM
  4. Operating system
    By sopranosomega in forum C Programming
    Replies: 6
    Last Post: 10-07-2002, 06:12 AM
  5. Operating System
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 115
    Last Post: 03-31-2002, 06:34 AM

Tags for this Thread