如何确定系统名称和删除一个文件(60分)

  • 主题发起人 主题发起人 llk
  • 开始时间 开始时间
L

llk

Unregistered / Unconfirmed
GUEST, unregistred user!
我要做一个小程序,需要知道系统名称(win2000.win98.win95.winnt.winme.winxp)
另外,还要删除一个文件(文件路径已知),怎么办?
请指教
 
小case,但好像有用,我也学学
 
DeleteFile('c:/text.txt') 這樣便可將c:/text.txt這個文件刪除
至於系統名稱有一個Api函數可以實現,名字忘記了
 
{--------------------------------------------------------------------------}
{1、获取当前Windows的版本}
const
cOsUnknown = -1;
cOsWin95 = 0;
cOsWin98 = 1;
cOsWin98SE = 2;
cOsWinME = 3;
cOsWinNT = 4;
cOsWin2000 = 5;
cOsXP = 6;


function GetOperatingSystem: Integer;
var
osVerInfo: TOSVersionInfo;
majorVer, minorVer: Integer;
begin
Result := cOsUnknown;
{ set operating system type flag }
osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
if GetVersionEx(osVerInfo) then
begin
majorVer := osVerInfo.dwMajorVersion;
minorVer := osVerInfo.dwMinorVersion;
case osVerInfo.dwPlatformId of
VER_PLATFORM_WIN32_NT: { Windows NT/2000 }
begin
if majorVer <= 4 then
Result := cOsWinNT
else if (majorVer = 5) and (minorVer = 0) then
Result := cOsWin2000
else if (majorVer = 5) and (minorVer = 1) then
Result := cOsXP
else
Result := cOsUnknown;
end;
VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME }
begin
if (majorVer = 4) and (minorVer = 0) then
Result := cOsWin95
else if (majorVer = 4) and (minorVer = 10) then
begin
if osVerInfo.szCSDVersion[1] = 'A' then
Result := cOsWin98SE
else
Result := cOsWin98;
end
else if (majorVer = 4) and (minorVer = 90) then
Result := cOsWinME
else
Result := cOsUnknown;
end;
else
Result := cOsUnknown;
end;
end
else
Result := cOsUnknown;
end;

{--------------------------------------------------------------------------}
{2、判断当前OS是否属于那一个}
function IsXP: Boolean;
var
OS: TOSVERSIONINFO;
begin
OS.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFO);
GetVersionEx(osv);
Result := (OS.dwPlatformId = VER_PLATFORM_WIN32_NT) and
(OS.dwMajorVersion = 5) and (OS.dwMinorVersion = 1);
end;

function IsWin2000: Boolean;
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := (OS.dwMajorVersion >= 5) and
(OS.dwPlatformId = VER_PLATFORM_WIN32_NT);
end;


function IsWinNT2: Boolean;
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := OS.dwPlatformId = VER_PLATFORM_WIN32_NT;
end;

{ or: }

function IsWinNT2: Boolean;
begin
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
end;


function IsWinME: Boolean;
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 90) and
(OS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
end;


function IsWin95: Boolean;
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := (OS.dwMajorVersion >= 4) and (OS.dwMinorVersion = 0) and
(OS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
end;
 
多人接受答案了。
 
后退
顶部