请问怎么读取注册表键值(100分)

S

sr_fh

Unregistered / Unconfirmed
GUEST, unregistred user!
请问:怎么读取HKEY_LOCAL_MACHINE下Software/Blizzard Entertainment/Starcraft/program
的键值?
 
拜托,你先查查TRegistry的帮助再问吧!
 
var
Reg :TRegistry;
Str : String;
begin
Reg :=TRegistry.Create;
try
Reg.RootKey :=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('Software/Blizzard Entertainment/Starcraft/program',True) then
begin
if Reg.ValueExists('...') then
Str :=Reg.ReadString('...');
end;
finally
Reg.CloseKey;
Reg.Free;
end;
end;
记得在uses里加入Registry单元。
 
1.下面是读写注册表的方式(读写键值是string, 用strToInt, 和 IntToStr进行转换)
function htwReadRegisry( RegKey :string ;
Default :string ;
MyRootKey : Hkey;
MyOpenKey :string): string ;
var
Registry: TRegistry;
S : string;
begin
Registry:= TRegistry.Create;
try
begin
Registry.RootKey :=MyRootKey;
// HKEY_CURRENT_USER;
Registry.OpenKey(MYOpenKey,false);
// Registry.OpenKey('/Software/MachineAdministrator',false);
S := Registry.ReadString(RegKey);
end
finally
begin
Registry.CloseKey;
Registry.Free;
end;
if Trim(S)='' then
Result := Default
else
Result := S;
end;

end;

procedure htwWriteRegisry(RegKey :string ;asValueTobewrited : string;
MyRootKey : Hkey;
MyOpenKey :string );
var
Registry: TRegistry;
begin
Registry:= TRegistry.Create;
try
begin
Registry.RootKey :=MyRootKey;
// HKEY_CURRENT_USER;
Registry.OpenKey(MyOpenKey,true);
//Registry.OpenKey('/Software/MachineAdministrator',true);
Registry.WriteString(RegKey,asValueTobewrited);
end
finally
begin
Registry.CloseKey;
Registry.Free;
end;
end;
end;

调用方法:
try
htwWriteRegisry('sShortDate','yyyy-MM-dd' ,HKEY_LOCAL_MACHINE, '/Control Panel/International');
htwWriteRegisry('sShortDate','yyyy-MM-dd' ,HKEY_LOCAL_MACHINE, '/.DEFAULT/Control Panel/International');
setlocaleinfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SDATE,'yyyy-MM-dd');
except
end;

///
var
sDialName :string;
try
sDialName:=htwReadRegisry('DialupName','我的连接' ,HKEY_CURRENT_USER, '/SoftWare/vgtable');
except
ShowMessage('写注册表失败');
end;

 
哇,兄弟们都写得很详细了
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
736
SUNSTONE的Delphi笔记
S
S
回复
0
查看
616
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
顶部