谢谢大家。我有我的方式,因为我是一个初学者,我不舒服$ IfNDef编译器指令。我已经使用Ken Whites的代码(How to check in delphi the OS version? Windows 7 or Server 2008 R2?)进行Windows检测,并使用Remy Lebeau示例(Resource Saving In System Directory)。它在德尔福XE2完美的作品。我的代码如下:
unit ApplicationWizard01;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons;
type
TMainForm = class(TForm)
BitBtn01: TBitBtn;
procedure BitBtn01Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
var
GetNativeSystemInfo: function(var SysInfo: TSystemInfo): BOOL stdcall = nil;
var
GetProductInfo: function (dwOSMajorVersion, dwOSMinorVersion,
dwSpMajorVersion, dwSpMinorVersion: DWORD;
var pdwReturnedProductType: DWORD): BOOL stdcall = nil;
implementation
{$R *.dfm}
function GetSysDir: string;
var
SystemDirectory: array[0..MAX_PATH] of Char;
begin
GetSystemDirectory(SystemDirectory, MAX_PATH - 1);
SetLength(Result, StrLen(SystemDirectory));
Result := IncludeTrailingPathDelimiter(SystemDirectory);
end;
function GetSysNativeDir: string;
var
WindowsDirectory: array[0..MAX_PATH] of Char;
begin
GetWindowsDirectory(WindowsDirectory, MAX_PATH - 1);
SetLength(Result, StrLen(WindowsDirectory));
Result := IncludeTrailingPathDelimiter(WindowsDirectory) + 'Sysnative\';
end;
procedure TMainForm.BitBtn01Click(Sender: TObject);
var
NTBres, BRes: Boolean;
OSVI: TOSVERSIONINFO;
OSVI_NT: TOSVERSIONINFOEX;
SI: TSystemInfo;
ResStream: TResourceStream;
ResourceSavingPathAndFileName : string;
begin
NTBRes := false;
try
OSVI_NT.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFOEX);
NTBRes := GetVersionEx(OSVI_NT);
OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
BRes := GetVersionEx(OSVI);
except
OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
BRes := GetVersionEx(OSVI);
end;
if (not BRes) and (not NTBres) then Exit;
Move(OSVI, OSVI_NT, SizeOf(TOSVersionInfo));
if Assigned(GetNativeSystemInfo) then GetNativeSystemInfo(SI) else GetSystemInfo(SI);
if (SI.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL) then
begin
ResourceSavingPathAndFileName := (GetSysDir);
ResStream := TResourceStream.Create(HInstance, 'DynamicLlinkLibraryWin32', RT_RCDATA);
try
ResStream.SaveToFile(ResourceSavingPathAndFileName + 'FileWin32.dll');
finally
ResStream.Free;
end;
end
else if (SI.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) then
begin
ResourceSavingPathAndFileName := (GetSysNativeDir);
ResStream := TResourceStream.Create(HInstance, 'DynamicLlinkLibraryWin64', RT_RCDATA);
try
ResStream.SaveToFile(ResourceSavingPathAndFileName + 'FileWin64.dll');
finally
ResStream.Free;
end;
end;
ShowMessage ('Resource Has Been Saved Successfully');
end;
initialization
@GetProductInfo := GetProcAddress(GetModuleHandle('KERNEL32.DLL'),
'GetProductInfo');
@GetNativeSystemInfo := GetProcAddress(GetModuleHandle('KERNEL32.DLL'),
'GetNativeSystemInfo');
end.
您是否知道1.您需要升级到那里写入,并且2.由于系统目录对于系统是私有的,因此应用程序不能在那里写入。所以,一旦你解决这个问题,你的应用程序将违反规则。 –
你提升了吗? http://en.wikipedia.org/wiki/User_Account_Control –
是清单是“AsAdministrator”。 –