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?
Detecting Vista
Miscellaneous Forums/Win32 Discussion/Detecting Vista 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)
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)
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.
Ah, those API calls, eh? I should really start to learn how to use those ;o)
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.
Cheers in advance.
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
SuperStrict Notify GetWindowsVersion() Function GetWindowsVersion$() ?Win32 Extern "Win32" Function GetVersionExW:Int(osVersion:Byte Ptr) EndExtern Type OSVERSIONINFO Field dwOSVersionInfoSize:Int Field dwMajorVersion:Int Field dwMinorVersion:Int Field dwBuildNumber:Int Field dwPlatformId:Int Field szCSDVersion:Short Ptr Method New() dwOSVersionInfoSize = SizeOf(Self) + 252 EndMethod EndType ? Local tmpOutput:OSVERSIONINFO = New OSVERSIONINFO If GetVersionExW(tmpOutput) Then Select tmpOutput.dwMajorVersion Case 6;Return "Windows Vista" Case 5 Select tmpOutput.dwMinorVersion Case 2;Return "Windows XP 64-bit / Windows Server 2003" Case 1;Return "Windows XP" Case 0;Return "Windows 2000" EndSelect Case 4 Select tmpOutput.dwMinorVersion Case 90;Return "Windows ME" Case 10;Return "Windows 98" Case 0;If tmpOutput.dwPlatformId = 2 Then Return "Windows NT 4.0" Else Return "WIndows 95" EndSelect EndSelect EndIf EndFunction
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
Thanks. Works a treat. Much appreciated.
For Seb:
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...
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...