by Get Real! » Sun May 08, 2011 12:00 pm
Thanks a million to those that responded… you saved me from wasting 2-3 hours setting up a Vista box just to get this! Ok, here’s the result… a routine that detects the Windows version via the very reliable %SYSTEMROOT% (not to be confused with %WINDIR%). This is in Pascal but it can easily be adopted in VB or other languages so use the code freely…
{-------------------------------------------------------------------}
{ Determines Windows version via %SYSTEMROOT%
0. Windows 2000/16-bit
1. Windows XP/32-bit
2. Windows XP/64-bit
3. Windows Vista/32-bit
4. Windows Vista/64-bit
5. Windows 7/32-bit
6. Windows 7/64-bit
}
{$A+,B-,D-,E-,F-,G+,I-,K-,L-,N+,O-,P-,Q-,R-,S-,T-,V-,W-,X-,Y-}
USES Dos;
{-------------------------------------------------------------------}
FUNCTION WindowsVersion:String;
VAR Win64,OS,S:String;
BEGIN
OS:='';
Win64:=GetEnv('PROGRAMFILES(X86)');
S:=GetEnv('SYSTEMROOT');
IF S='C:\Windows' THEN {Windows 7 or Vista}
BEGIN
IF GetEnv('PSModulePath')<>'' THEN
OS:='Windows 7' ELSE OS:='Windows Vista';
END ELSE
IF S='C:\WINDOWS' THEN {Windows XP}
BEGIN
OS:='Windows XP';
END ELSE
IF S='C:\WINNT' THEN {Windows 2000 or NT 5.1}
BEGIN
OS:='Windows 2000/16-bit'; Exit;
END ELSE
IF S='C:\WINNT35' THEN {NT 3.5}
BEGIN
OS:='Windows NT 3.5'; Exit;
END ELSE
BEGIN {NT Terminal Server etc, but who cares!}
OS:='Undetermined'; Exit;
END;
IF Win64='' THEN OS:=OS+'/32-bit' ELSE OS:=OS+'/64-bit';
WindowsVersion:=OS;
END;
{-------------------------------------------------------------------}
BEGIN
Writeln(WindowsVersion);
END.