Thread: Identifying Windows Version, Outside of Windows

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    Identifying Windows Version, Outside of Windows

    I'm trying to programmatically find the version of Windows operating system that has it's primary partition mounted within my Linux box. Does anyone know how this can be reliably done?

    I was considering reading one of the registry hives, but I don't know how reliable that would be across versions, and I don't know if that would be easy to find out without actually having each version with me. Not to mention, I don't know where I would find it, and hives can get corrupted.

    Right now, I'm liking the idea of reading the boot.ini file. The W2K box I'm on now has
    Code:
    [boot loader]
    timeout=30
    default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
    [operating systems]
    multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect
    and the XP box I used to have looked identical, except for the OS name string. If you're running Vista or 7, it would be great if you could post your boot.ini file for me. I know the string could be changed (I've done it before) without messing anything up, so this could not work, but I'm guessing that 99.99% of people don't.

    Thanks

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    One way: KB307394
    And a more appropriate way if the client machine has Vista or above: GetProductInfo()
    Last edited by Mario F.; 12-21-2009 at 06:28 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Mario F. View Post
    One way: KB307394
    And a more appropriate way if the client machine has Vista or above: GetProductInfo()
    How's he supposed to call Windows functions on a Linux machine?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    System::Environment::OSVersion and GetProductInfo() are Windows methods.
    I need to figure this out using only the files (or maybe a registry hive), as the primary partition will be mounted somewhere, and my program will be running inside of Linux.

    EDIT: Right. brewbuck's faster.
    Last edited by Yarin; 12-21-2009 at 06:46 PM.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    My bad. Didn't read the question properly.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Windows 7 and Windows Vista have no boot.ini files:

    Windows Vista startup process - Wikipedia, the free encyclopedia
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  7. #7
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    A dumb solution that might/might not work->Call wine on an standalone exe which prints the OS version. ;-)
    ver. But I couldn't find ver.exe anywhere on my system. However, I could find winver.exe(the GUI variant of ver) on vista.
    Good Luck.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    wine emulates a Windows version. It doesn't use an existing installation.

  9. #9
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    True. But I am talking about running the programs in the mounted OS not the emulated one. I guess this method highly depend on how such programs print the version though. If it's a simple print to the screen then i would expect it to work. Maybe reverse engineering the exeutable might come handy here.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Or maybe it just reads a value from registry and print it out. From wine's registry.

  11. #11
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Quote Originally Posted by cyberfish View Post
    Or maybe it just reads a value from registry and print it out. From wine's registry.
    That would be nasty but I think that would be the case now that you mention it. I dunno as i am not into windows programming.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  12. #12
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    I have never done any Windows programming . It was just a wild guess.

    It's easy to check, though.

    Attached is my XP Pro SP2's winver (change the extension to exe), try running it?

  13. #13
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Quote Originally Posted by cyberfish View Post
    I have never done any Windows programming . It was just a wild guess.

    It's easy to check, though.

    Attached is my XP Pro SP2's winver (change the extension to exe), try running it?
    You are correct. It outputs correctly as Vista on my PC. So it must be getting the job done by reading the values from the registry. Silly of me to expect them to write a different program for each version instead of reusing the existing one.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  14. #14
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Just read the value from the registry (it's fairly easy to parse). That is, once you've found the correct hive.

  15. #15
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Some facts.

    1. The "ver" command is a part of cmd.exe. It is not a program itself.
    2. "winver" uses GetVersionEx to get the platform version
    3. GetVersionEx calls RtlGetVersion, which is in ntdll.dll
    4. RtlGetVersion accesses a global structure within the ntdll.dll image which contains the platform version info.

    The registry doesn't come into it at all. This is just what I managed to figure out in 15 minutes using IDA Pro.

    Also, version of WHAT? One approach I thought of would be to fingerprint the ntoskrnl.exe file and develop a mapping of fingerprints to major versions. But the OS version is much more than just the kernel version -- it's also going to include which service packs are installed, the patch level of ntdll.dll, and lots of other crap.

    To what accuracy do you need to determine the version? What are you trying to do?

    EDIT: In case it's not clear, based on what I discovered above, running winver.exe from within Wine would just give a Wine version, not the real version. But I had considered Wine, yes...
    Last edited by brewbuck; 12-22-2009 at 12:01 AM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows 7, First Impressions
    By Mario F. in forum General Discussions
    Replies: 16
    Last Post: 08-11-2009, 06:46 AM
  2. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. MS Windows Welsh Language Version Available
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 12-03-2004, 04:59 PM
  5. Windows upgrade question
    By 7smurfs in forum Tech Board
    Replies: 11
    Last Post: 10-20-2004, 01:51 PM