Detecting Vista

Archives Forums/Win32 Discussion/Detecting Vista

JazzieB(Posted 2007) [#1]
Simple enough question... How can I find out if my program is running under Windows Vista? Does the environment variable %OS% return something other than "Windows_NT", as it does on XP?


JazzieB(Posted 2007) [#2]
Well, as nobody answered and now that I have Vista to check this out...

The environment variable OS still returns "Windows_NT", which is ever so helpful ... not. So, the only way that I can see at the moment is by checking for the user's personal folder instead (HOMEDRIVE+HOMEPATH). You see, under Vista it will start with "C:\Users\" and not "C:\Documents and Settings\", as it does under XP.

Just in case anyone was interested ;o)


Timeslip(Posted 2007) [#3]
Assuming your program is able to use the windows api, just use GetVersionEx. Vista returns 6.0, 2000/xp/2003 are 5.0, 5.1 and 5.2 respectively.


JazzieB(Posted 2007) [#4]
Ah, those API calls, eh? I should really start to learn how to use those ;o)


JazzieB(Posted 2007) [#5]
Don't suppose anybody could throw a quick example together, could they? I don't have a clue when it comes to all this Extern stuff :o(

Cheers in advance.


SebHoll(Posted 2007) [#6]
Here's what I've managed to come up with and it works fine on my Vista computer...



I'm not sure how memory safe simply increasing the size of the type is as the system will be writing to memory outside the type structure. I tried to use a byte array to pad out the type but it simply stores a 1 byte memory pointer (I think because Max doesn't support type static arrays). :-?

Hope this helps,

Seb


JazzieB(Posted 2007) [#7]
Thanks. Works a treat. Much appreciated.


grable(Posted 2007) [#8]
For Seb:
I'm not sure how memory safe simply increasing the size of the type is as the system will be writing to memory outside the type structure.


Changing "Field szCSDVersion:Short Ptr" into 16 Longs (128/8) should take care of that ;)

EDIT: or maybe 32 if your using the Widechar version...