tags:

views:

219

answers:

2

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
It only tells difference between XP's
Can you please elaborate?
avakar
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
+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
Also worth considering [SHGetFolderPath](http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx).
Nick Meyer