关于注册表的问题(50分)

  • 主题发起人 主题发起人 iceleafage
  • 开始时间 开始时间
I

iceleafage

Unregistered / Unconfirmed
GUEST, unregistred user!
请问注册表中的字符串,二进制,DWORD值,怎么用delphi的什么语句来
写,如二进制值用delphi怎么写在注册表中。
 
字符串:TRegistry.WriteString
二进制: TRegistry.WriteBinaryData
DWord: TRegistry.WriteInteger;
uses
TRegistry;
...
procedure SaveBinary(a: TRect);
var
Reg: TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('Software/sss/ddd', True) then
Reg.WriteBinaryData('xxx', a, SizeOf(a));
Reg.CloseKey
finally
Reg.Free
end
end;
 
写入一个二进制数据可以用WriteInteger
其实WriteBinary主要用来写入Record和数组之类的。
procedure SetAutoDial;
var
TempInteger: Array [1..4] of Char;
begin
with TRegistry.Create do
try
RootKey := HKEY_CURRENT_USER;
if OpenKey('/Software/Microsoft/Windows/CurrentVersion/Internet Settings', false) then
begin
try
ReadBinaryData('EnableAutodial', TempInteger, 4);
except
end;
if TempInteger[1] = #0 then
begin
TempInteger[1]:= #1;
try
WriteBinaryData('EnableAutodial', TempInteger, 4);
except
end;
try
WriteBinaryData('NoNetAutodial', TempInteger, 4);
except
end;
end;
end;
finally
CloseKey;
Free;
end;
end;

读写都可以做了,要 show 它出来就简单了
 
我给你转帖一个,我就是用它实现了二进制值的写入!
上面是写入,下面是读入:
var
Reg : TRegistry;
Buf : array [1..4] of Byte;
//因为你写入的数据是00 00 00 01,四个字节,所以数组大小定义为4了;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
//这里给数组赋值,对应关系看下面
// 00 00 00 01
// Buf[1] Buf[2] Buf[3] Buf[4]
Buf[1] := 00;
Buf[2] := 00;
Buf[3] := 00;
Buf[4] := 01;
Reg.WriteBinaryData('NoSaveSettings', Buf , SizeOf(Buf));
//WriteBinaryData的第三个参数是你要写入的节字数大小,SizeOf(Buf)是得到数组Buf的大小(即是4)。
//如果你将这句改为
//Reg.WriteBinaryData('NoSaveSettings', Buf , 2);
//那么写入的只是Buf[1]和Buf[2],如果打开注册表看,这个键的值是00 00
finally
Reg.Free;
end;
----------------------------------------------
var
Reg : TRegistry;
Buf : array [1..4] of Byte;
BufSize: Integer;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
BufSize := Reg.GetDataSize('NoSaveSettings');
if BufSize <> -1 then
Reg.ReadBinaryData('NoSaveSettings', Buf , BufSize);
//.............
finally
Reg.Free;
end;

 
后退
顶部