注册表操作双字节DWord值的问题,210高分请教 ( 积分: 210 )

  • 主题发起人 oOkokoOo
  • 开始时间
O

oOkokoOo

Unregistered / Unconfirmed
GUEST, unregistred user!
本人很菜哦,初来乍到还请大家多关照
现在一问题请大家指点,我要在注册表一根键下写一个子键值项(DWord)
Root=Hkey_Current_User
在以上根键下的Software/Software/Microsoft/Windows/CurrentVersion/Policies下新建子键“System”;即:Software/Software/Microsoft/Windows/CurrentVersion/Policies/System
然后在system里写一个Dword(双字节值)的键值项,名称为“DisableTaskMgr”,数值为“1”
具体代码实现思路是:先判断子项“System”是否存在,若没有则新建,再判断键值项“DisableTaskMgr”是否存在,若不存在则新建,并把其数值设为“1”。

delphi里操作注册表我就双字节(DWord)不会了,我在百度和GOOGLE上都搜索了没找到满意的答案;还请各位高手贴出代码和详细说明来,不要给我一个类似问题的链接或者只提一个思路,我只要实现代码和详细的说明,因为我菜鸟嘛,呵呵
 
DWord是双字,而不是双字节。

var
tmpReg: TRegistry;
begin
tmpReg := TRegistry.Create;
try
tmpReg.RootKey := Hkey_Current_User;
if not tmpReg.KeyExists('Software/Software/Microsoft/Windows/CurrentVersion/Policies') then
tmpReg.CreateKey('Software/Software/Microsoft/Windows/CurrentVersion/Policies');
tmpReg.OpenKey('Software/Software/Microsoft/Windows/CurrentVersion/Policies', False);
try
tmpReg.WriteInteger('DisableTaskMgr', 1);
finally
tmpReg.CloseKey;
end;
finally
tmpReg.Free;
end;
 
晕 楼上的解决了 来迟了。。。
var
tmpReg: TRegistry;
begin
tmpReg := TRegistry.Create;//建注册表类
try
tmpReg.RootKey := =Hkey_Current_User;// 根键
if not tmpReg.KeyExists //判断键是否存在('Software/Software/Microsoft/Windows/CurrentVersion/Policies') then
tmpReg.OpenKey // 打开指定键,True表示键不存在则新建,false 不新建('Software/Software/Microsoft/Windows/CurrentVersion/Policies', True);
try
tmpReg.WriteInteger('DisableTaskMgr', 1);
finally
tmpReg.CloseKey;// 关闭打开的注册表键句柄
end;
finally
tmpReg.Free; //释放

end;
不用create 吧 判断了 直接openkey的时候用true 就会建了。
 
谢谢2位,我想我说错了,我要问的是WriteBinaryData(const Name:String;Var Buffer;BuffSize:integer) 的用法及其具体实现代码说明
WriteInteger(),WriteString()。。。什么的我都会啊
 
For Example:

uses ...,Registry;
procedure TForm1.Button1Click(Sender: TObject);
var
myReg: TRegistry;
const
myArray: Array[0..3] of Byte = ($01, $00, $00, $00);
begin
myReg := TRegistry.Create;
try
myReg.RootKey := HKEY_CURRENT_USER;
if myReg.OpenKey('Control Panel/VDop', True) then
myReg.WriteBinaryData('0000', myArray, 4);
finally
myReg.Free;
end;
end;
上面是论坛中的,自己又给你写了一个
procedure TForm1.Button2Click(Sender: TObject);
var
myReg: TRegistry;
buf: PChar;
begin
buf := PChar(AllocMem(32));
StrCopy(buf,PChar(string('abcd1234')));
myReg := TRegistry.Create;
myReg.RootKey := HKEY_LOCAL_MACHINE;
myReg.OpenKey('SoftWare/DelphiBBS',True);
myReg.WriteBinaryData('bbs',buf^,32);
myReg.Free;
end;
 
谢谢各位了
 
谢谢各位了
 

Similar threads

S
回复
0
查看
745
SUNSTONE的Delphi笔记
S
S
回复
0
查看
625
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部