운영체제가 XP 인지 판단을 어떻게 할까요?
게시판을 검색해봐도 NT계열인가 아닌가만 알수있을뿐 2000과 XP를 같은걸로 판단을 해주는군요.
2000과 XP는 같은 NT 계열이기는 하지만 폴더의 이름과 배치등이 서로 다르더군요. 위치를 정확히 찾아 카피를 해줘야 하는 프로그램이라서 실행시 에러가 나는군요.
방법이 없을까요?
쩝 바뻐성 걍 제가 썼던거 그대로 올립니다. 그래서
중간에 쓸데 없는 코드도 있을수도 모자란 코드도 있을듯...^^;;
제가 기본적이 상수랑 형은 같이 적어놓았습니다.
쩝....참고로 XP pro와 home 에디션이 정확히 구분이 되는지 모르겠습니다.
홈에서 테스트 해봤는데 프로로 나오더군여 근데 바뽀성 안고쳤습니다.
//내가 사용한 함수
procedure DisplaySystemVersion();
var
osvi : TOSVERSIONINFOEX;
bOsVersionInfoEx :Boolean;
hKeys : HKEY;
szProductType : array [1..80] of Char;
dwBufLen : DWORD;
szCSDVersion : string;
begin
// TOSVERSIONINFOEX 형을 GetVersionEx 함수로 호출한다.
// 만약 실패하면 TOSVERSIONINFO 형식으로 호출한다
ZeroMemory(@osvi, sizeof(TOSVERSIONINFOEX));
osvi.dwOSVersionInfoSize := sizeof(TOSVERSIONINFOEX);
bOsVersionInfoEx := GetVersionEx(osvi);
if not (bOsVersionInfoEx) then
begin
osvi.dwOSVersionInfoSize := sizeof (TOSVERSIONINFO);
if not ( GetVersionEx (osvi) ) then
begin
osFullName := MRSUnknown;
Exit;
end;
end;
case osvi.dwPlatformId of
VER_PLATFORM_WIN32_NT:
begin
if ( osvi.dwMajorVersion <= 3 ) then
begin
osFullName:= WINNT_NAME;
end;
if ( osvi.dwMajorVersion <= 4 ) then
osFullName:=WINNT_NAME;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
begin
osFullName:=WINNT_2000;
ovdType := ovdWin2000;
end;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
begin
osFullName:= WINNT_XP ;
ovdType := ovdWinXP;
end;
if bOsVersionInfoEx then
begin
if osvi.wProductType = VER_NT_WORKSTATION then
begin
if ( osvi.wSuiteMask = VER_SUITE_PERSONAL ) then
begin
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
osFullName := osFullName + WINNT_PER;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
osFullName := osFullName + WINNT_HOME ;
end
else
osFullName := osFullName + WINNT_PRO;
end
// end;
else if osvi.wProductType = VER_NT_SERVER then
begin
if osvi.wSuiteMask = VER_SUITE_DATACENTER then
osFullName := osFullName + WINNT_DATSVR
else if osvi.wSuiteMask = VER_SUITE_ENTERPRISE then
begin
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
osFullName := osFullName + WINNT_ADSVR;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
osFullName := WINNT_NET + WINNT_ENTSVR ;
end
else
begin
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
osFullName := osFullName + WINNT_SERVER;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
osFullName := WINNT_NET + WINNT_ENTSVR ;
end;
end;
end
else
begin
RegOpenKeyEx( HKEY_LOCAL_MACHINE,PChar('SYSTEM\CurrentControlSet\Control\ProductOptions'),
0, KEY_QUERY_VALUE, hKeys );
RegQueryValueEx( hKeys, 'ProductType', nil, nil, PBYTE(@szProductType), @dwBufLen);
RegCloseKey( hKeys );
if ( lstrcmpi( 'WINNT', @szProductType) = 0 ) then
osFullName := osFullName + 'Workstation ';
if ( lstrcmpi( 'SERVERNT', @szProductType) = 0 ) then
osFullName := osFullName + 'Server ';
if ( osvi.dwMajorVersion = 3) and (osvi.dwMinorVersion = 51 ) then
begin
osFullName := osFullName + '3.51 ';
ovdType := ovdWinNT351;
end;
if ( osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 0 ) then
begin
osFullName := osFullName + '4.0 ';
ovdType := ovdWinNT40;
end;
end;
osFullBuild := format('%d.%d.%d',[osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber and $FFFF ]);
osCSDVersion:=osvi.szCSDVersion;
end;// end case VER_PLATFORM_WIN32_NT
VER_PLATFORM_WIN32_WINDOWS:
begin
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 0) then
begin
osFullName := WIN95_NAME;
ovdType := ovdWin95;
if osvi.szCSDVersion = 'C' then
osFullName :=osFullName+ WIN95_OSR2 ;
end;
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 10) then
begin
osFullName := WIN98_NAME ;
ovdType := ovdWin98;
if trim(osvi.szCSDVersion) = 'A' then
osFullName :=osFullName+ WIN98_SE ;
end;
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 90) then
begin
osFullName :=WINME_NAME;
ovdType := ovdWinME;
end;
osCSDVersion:=osvi.szCSDVersion;
osFullBuild := format('%d.%d %d %s',[osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber and $FFFF,osCSDVersion ]);
end; //end case VER_PLATFORM_WIN32_WINDOWS
VER_PLATFORM_WIN32s:
begin
osFullName :=WIN32_NAME;
osCSDVersion:=osvi.szCSDVersion;
osFullBuild := format('%d.%d %d %s',[osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber and $FFFF,osCSDVersion ]);
end;
end;//end all case
end;
중간에 쓸데 없는 코드도 있을수도 모자란 코드도 있을듯...^^;;
제가 기본적이 상수랑 형은 같이 적어놓았습니다.
쩝....참고로 XP pro와 home 에디션이 정확히 구분이 되는지 모르겠습니다.
홈에서 테스트 해봤는데 프로로 나오더군여 근데 바뽀성 안고쳤습니다.
msdn욜라 찾아서 데파이로 바꾼겁니다...힘들었는뎅......배아포....
//선언부--------
type
LPOSVERSIONINFOEX = ^TOSVERSIONINFOEX;
POSVERSIONINFOEX = ^TOSVERSIONINFOEX;
_OSVERSIONINFOEX = record
dwOSVersionInfoSize : DWORD;
dwMajorVersion : DWORD;
dwMinorVersion : DWORD;
dwBuildNumber :DWORD;
dwPlatformId : DWORD;
szCSDVersion :array [0..127] of char;
wServicePackMajor : WORD;
wServicePackMinor:WORD;
wSuiteMask:WORD;
wProductType : BYTE;
wReserved : BYTE;
end;
TOSVERSIONINFOEX = _OSVERSIONINFOEX;
//
{ WINNT.H =====================================================================}
//
const VER_SERVER_NT = $80000000 ;
const VER_WORKSTATION_NT = $40000000 ;
const VER_SUITE_SMALLBUSINESS = $00000001 ;
const VER_SUITE_ENTERPRISE = $00000002 ;
const VER_SUITE_BACKOFFICE = $00000004 ;
const VER_SUITE_COMMUNICATIONS = $00000008 ;
const VER_SUITE_TERMINAL = $00000010 ;
const VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020 ;
const VER_SUITE_EMBEDDEDNT = $00000040 ;
const VER_SUITE_DATACENTER = $00000080 ;
const VER_SUITE_SINGLEUSERTS = $00000100 ;
const VER_SUITE_PERSONAL = $00000200 ;
const VER_SUITE_BLADE = $00000400 ;
//
// RtlVerifyVersionInfo() type mask bits
//
const VER_MINORVERSION = $0000001 ;
const VER_MAJORVERSION = $0000002 ;
const VER_BUILDNUMBER = $0000004 ;
const VER_PLATFORMID = $0000008 ;
const VER_SERVICEPACKMINOR = $0000010 ;
const VER_SERVICEPACKMAJOR = $0000020 ;
const VER_SUITENAME = $0000040 ;
const VER_PRODUCT_TYPE = $0000080 ;
//
// RtlVerifyVersionInfo() os product type values
//
const VER_NT_WORKSTATION = $0000001 ;
const VER_NT_DOMAIN_CONTROLLER = $0000002 ;
const VER_NT_SERVER = $0000003 ;
//
{end WINNT.H ==================================================================}
//
const WIN32_NAME = 'Microsoft Win32s ' ;
const WIN95_NAME = 'Windows 95 ' ;
const WIN95_OSR2 = 'OSR2 ' ;
const WIN98_NAME = 'Windows 98 ' ;
const WIN98_SE = 'SE ' ;
const WINME_NAME = 'Windows ME ' ;
const WINNT_HOME = 'HomeEdition ' ;
const WINNT_PER = 'Personal ' ;
const WINNT_PRO = 'Professional ' ;
const WINNT_SERVER = 'Server ' ;
const WINNT_ADSVR = 'Advanced Server ' ;
const WINNT_DATSVR = 'DataCenter Server ' ;
const WINNT_ENTSVR = 'Enterprise Server ' ;
const WINNT_NAME = 'Windows NT ' ;
const WINNT_2000 = 'Windows 2000 ' ;
const WINNT_XP = 'Windows XP ' ;
const WINNT_NET = 'Windows .NET ' ;
//선언부--------끝
//내가 사용한 함수
procedure DisplaySystemVersion();
var
osvi : TOSVERSIONINFOEX;
bOsVersionInfoEx :Boolean;
hKeys : HKEY;
szProductType : array [1..80] of Char;
dwBufLen : DWORD;
szCSDVersion : string;
begin
// TOSVERSIONINFOEX 형을 GetVersionEx 함수로 호출한다.
// 만약 실패하면 TOSVERSIONINFO 형식으로 호출한다
ZeroMemory(@osvi, sizeof(TOSVERSIONINFOEX));
osvi.dwOSVersionInfoSize := sizeof(TOSVERSIONINFOEX);
bOsVersionInfoEx := GetVersionEx(osvi);
if not (bOsVersionInfoEx) then
begin
osvi.dwOSVersionInfoSize := sizeof (TOSVERSIONINFO);
if not ( GetVersionEx (osvi) ) then
begin
osFullName := MRSUnknown;
Exit;
end;
end;
case osvi.dwPlatformId of
VER_PLATFORM_WIN32_NT:
begin
if ( osvi.dwMajorVersion <= 3 ) then
begin
osFullName:= WINNT_NAME;
end;
if ( osvi.dwMajorVersion <= 4 ) then
osFullName:=WINNT_NAME;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
begin
osFullName:=WINNT_2000;
ovdType := ovdWin2000;
end;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
begin
osFullName:= WINNT_XP ;
ovdType := ovdWinXP;
end;
if bOsVersionInfoEx then
begin
if osvi.wProductType = VER_NT_WORKSTATION then
begin
if ( osvi.wSuiteMask = VER_SUITE_PERSONAL ) then
begin
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
osFullName := osFullName + WINNT_PER;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
osFullName := osFullName + WINNT_HOME ;
end
else
osFullName := osFullName + WINNT_PRO;
end
// end;
else if osvi.wProductType = VER_NT_SERVER then
begin
if osvi.wSuiteMask = VER_SUITE_DATACENTER then
osFullName := osFullName + WINNT_DATSVR
else if osvi.wSuiteMask = VER_SUITE_ENTERPRISE then
begin
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
osFullName := osFullName + WINNT_ADSVR;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
osFullName := WINNT_NET + WINNT_ENTSVR ;
end
else
begin
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0 ) then
osFullName := osFullName + WINNT_SERVER;
if ( osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1 ) then
osFullName := WINNT_NET + WINNT_ENTSVR ;
end;
end;
end
else
begin
RegOpenKeyEx( HKEY_LOCAL_MACHINE,PChar('SYSTEM\CurrentControlSet\Control\ProductOptions'),
0, KEY_QUERY_VALUE, hKeys );
RegQueryValueEx( hKeys, 'ProductType', nil, nil, PBYTE(@szProductType), @dwBufLen);
RegCloseKey( hKeys );
if ( lstrcmpi( 'WINNT', @szProductType) = 0 ) then
osFullName := osFullName + 'Workstation ';
if ( lstrcmpi( 'SERVERNT', @szProductType) = 0 ) then
osFullName := osFullName + 'Server ';
if ( osvi.dwMajorVersion = 3) and (osvi.dwMinorVersion = 51 ) then
begin
osFullName := osFullName + '3.51 ';
ovdType := ovdWinNT351;
end;
if ( osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 0 ) then
begin
osFullName := osFullName + '4.0 ';
ovdType := ovdWinNT40;
end;
end;
osFullBuild := format('%d.%d.%d',[osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber and $FFFF ]);
osCSDVersion:=osvi.szCSDVersion;
end;// end case VER_PLATFORM_WIN32_NT
VER_PLATFORM_WIN32_WINDOWS:
begin
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 0) then
begin
osFullName := WIN95_NAME;
ovdType := ovdWin95;
if osvi.szCSDVersion = 'C' then
osFullName :=osFullName+ WIN95_OSR2 ;
end;
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 10) then
begin
osFullName := WIN98_NAME ;
ovdType := ovdWin98;
if trim(osvi.szCSDVersion) = 'A' then
osFullName :=osFullName+ WIN98_SE ;
end;
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 90) then
begin
osFullName :=WINME_NAME;
ovdType := ovdWinME;
end;
osCSDVersion:=osvi.szCSDVersion;
osFullBuild := format('%d.%d %d %s',[osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber and $FFFF,osCSDVersion ]);
end; //end case VER_PLATFORM_WIN32_WINDOWS
VER_PLATFORM_WIN32s:
begin
osFullName :=WIN32_NAME;
osCSDVersion:=osvi.szCSDVersion;
osFullBuild := format('%d.%d %d %s',[osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber and $FFFF,osCSDVersion ]);
end;
end;//end all case
end;