Is their a way in C to diferentiate between Vista and XP. Reason being is the the path I use is different in both.
+3
A:
You can get the version of your Windows OS by calling GetVersionEx
.
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof vi;
GetVersionEx(&vi);
if (vi.dwMajorVersion >= 6)
// Windows Vista or newer
else
// Windows XP or older
avakar
2009-07-10 05:11:19
It only tells difference between XP's
2009-07-10 05:14:04
Can you please elaborate?
avakar
2009-07-10 05:22:31
I'm fairly sure it does tell the difference between different versions correctly.I think `5.something` is XP, `6` is Vista and `6.1` is Windows 7.
SCdF
2009-07-10 05:56:53
+2
A:
You shouldn't have platform specific paths hard-coded into your application. There are environment variables for these things.
Open up a command prompt and type "set" to view a list of them. Several of these have been standard since Windows 95. Important environment variables to note are...
- HOME
- APPDATA
- ProgramFiles
- SystemRoot
- ALLUSERSPROFILE
So for example...
char * path; path = getenv("HOME"); printf(path);
Have a poke around your target versions of windows to see what variables are common between the two.
edit: python has made me lazy with string manipulation, fixed example code.
burito
2009-07-10 05:27:40
Also worth considering [SHGetFolderPath](http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx).
Nick Meyer
2009-07-10 13:01:06