此函式旨在回傳從注冊表請求的整數值。
我不能使用 TRegistry 物件,因為如果在 64 位作業系統上呼叫注冊表的程式是 32 位,它不會回傳正確的值,它將回傳最大值 10000。
如果程式從 IDE 內運行,則此函式回傳正確的值,但如果在 IDE 外運行則失敗。
function LB_ReadRegistryInteger(strSubKey: String;
strValueName: String): Integer;
// *****************************************************************************
// this function will read the registry and return the integer value for the key
// will work for 32 or 64 bit windows.
// *****************************************************************************
const const_KEY_WOW64_64KEY = $000000100; // value for KEY_WOW64_64KEY
var Key: HKey; // key value
TheInt: Integer; // return int value
IntSize: Integer; // integer size
TheType: Integer; // Type of data that is going to be read
begin
Result := 0; // default error return value
TheType := REG_DWORD; // Type of data that is going to be read
IntSize := SizeOf(TheInt);; // set size of int
// if can get key and read the key
if RegOpenKeyEx(HKEY_LOCAL_MACHINE,PChar(strSubKey),0
,(KEY_READ or const_KEY_WOW64_64KEY),Key) = ERROR_SUCCESS then
if RegQueryValueEx(Key,PChar(strValueName),nil
,@TheType,@TheInt,@IntSize) = ERROR_SUCCESS then
Result := TheInt; // result is value returned
RegCloseKey(Key); // close the registry
end; // of LB_ReadRegistryInteger
怎么稱呼。
// get the GDIProcessHandleQuota
TheValue := LB_ReadRegistryInteger('\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows'
,'GDIProcessHandleQuota');
uj5u.com熱心網友回復:
我無法使用該
TRegistry物件
是的,您可以將KEY_WOW64_64KEY標志與TRegistry. 只需將其應用于TRegistry.Access屬性,例如:
function LB_ReadRegistryInteger(strSubKey: String;
strValueName: String): Integer;
const
const_KEY_WOW64_64KEY = $000000100;
var
Reg: TRegistry;
begin
Result := 0;
Reg := TRegistry.Create;
try
Reg.Access := KEY_QUERY_VALUE or const_KEY_WOW64_64KEY;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey(strSubKey, False) then
try
//if Reg.ValueExists(strValueName) then
Result := Reg.ReadInteger(strValueName);
except
end;
finally
Reg.Free;
end;
end;
這應該可以正常作業,因為該TRegistry.OpenKey()方法將TRegistry.Access屬性的值按原樣傳遞給RegOpenKeyEx()和RegCreateKeyEx()API 函式 - 即使在 Delphi 7 中,它本身還不支持KEY_WOW64_...標志。
在 Delphi 2007 之前,該TRegistry.OpenKeyReadOnly()方法完全忽略了該TRegistry.Access屬性。但是,在本機支持KEY_WOW64_...標志的更高版本中,OpenKeyReadOnly()將尊重屬性KEY_WOW64_...中的標志TRegistry.Access,例如:
function LB_ReadRegistryInteger(strSubKey: String;
strValueName: String): Integer;
var
Reg: TRegistry;
begin
Result := 0;
Reg := TRegistry.Create;
try
Reg.Access := KEY_WOW64_64KEY;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly(strSubKey) then
try
//if Reg.ValueExists(strValueName) then
Result := Reg.ReadInteger(strValueName);
except
end;
finally
Reg.Free;
end;
end;
uj5u.com熱心網友回復:
您需要從鍵名中洗掉第一個反斜杠,因此將其稱為
TheValue := LB_ReadRegistryInteger('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows'
,'GDIProcessHandleQuota');
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/516714.html
