Tof*_*nov 3 windows delphi registry 64-bit 32bit-64bit
我认为这个问题已经被问到了,但我找不到适合我的解决方案.我在Windows 7旗舰版,64位下使用Delphi 7.实际上我开始在32位操作系统下编写应用程序,但随后更改了PC,所以现在更改为64.在我的程序中,我使用注册过程,从Windows的PROGID值生成许可证ID.不幸的是它没有读取值,似乎它正在查找不同的文件夹,可能是由Windows 64重定向到32位注册表.你能帮我吗?这是我使用的代码:
Registry := TRegistry.Create(KEY_READ OR $0100);
try
Registry.Lazywrite := false;
Registry.RootKey := HKEY_LOCAL_MACHINE;
if CheckForWinNT = true then
Begin
if not Registry.OpenKeyReadOnly('\Software\Microsoft\Windows NT\CurrentVersion') then showmessagE('cant open');
end
else
Registry.OpenKeyReadOnly('\Software\Microsoft\Windows\CurrentVersion');
result := Registry.ReadString('ProductID');
Registry.CloseKey;
finally
Registry.Free;
end; // try..finally
Run Code Online (Sandbox Code Playgroud)
另外,您知道如何在Delphi 7中查找程序是在64位还是32位计算机下运行?
The*_*Fox 12
您已经问过这个问题,请参阅Delphi 7中的Windows 7中的Registry ReadString方法.
所以你知道你必须在TRegistry.Create中添加$ 0100.您的代码的问题是您使用OpenKeyReadOnly将注册表的Access属性重置为KEY_READ,因此KEY_READ or $0100
丢失.
只需使用OpenKey而不是OpenKeyReadOnly,这不会重置您的Access属性.
下面是一些Delphi 7代码,用于检测您是否在64位操作系统中运行:
function Is64BitOS: Boolean;
type
TIsWow64Process = function(Handle:THandle; var IsWow64 : BOOL) : BOOL; stdcall;
var
hKernel32 : Integer;
IsWow64Process : TIsWow64Process;
IsWow64 : BOOL;
begin
// we can check if the operating system is 64-bit by checking whether
// we are running under Wow64 (we are 32-bit code). We must check if this
// function is implemented before we call it, because some older versions
// of kernel32.dll (eg. Windows 2000) don't know about it.
// see http://msdn.microsoft.com/en-us/library/ms684139%28VS.85%29.aspx
Result := False;
hKernel32 := LoadLibrary('kernel32.dll');
if (hKernel32 = 0) then RaiseLastOSError;
@IsWow64Process := GetProcAddress(hkernel32, 'IsWow64Process');
if Assigned(IsWow64Process) then begin
IsWow64 := False;
if (IsWow64Process(GetCurrentProcess, IsWow64)) then begin
Result := IsWow64;
end
else RaiseLastOSError;
end;
FreeLibrary(hKernel32);
end;
Run Code Online (Sandbox Code Playgroud)
(在这里无耻地剽窃我自己)
看起来你正在传递KEY_WOW64_64KEY($ 0100),所以你应该看看64位注册表分支.如果要查看32位注册表分支,则应传递KEY_WOW64_32KEY($ 0200).
归档时间: |
|
查看次数: |
23593 次 |
最近记录: |