请大虾们帮我看看代码,到底哪里错了? (50分)

  • 主题发起人 主题发起人 jjnb
  • 开始时间 开始时间
J

jjnb

Unregistered / Unconfirmed
GUEST, unregistred user!
运行时好象第二个if …… then
不起作用,是不是语法错了?
procedure TForm1.Button1Click(Sender: TObject);
var reg:tregistry;
begin
reg:=tregistry.Create ;
try
reg.RootKey :=HKEY_LOCAL_MACHINE;
if reg.openkey('System/CurrentControlSet/Services/LanmanServer/Parameters',true)
then
begin
reg.WriteInteger('AutoShareServer', 0);
reg.WriteInteger('AutoShareWks', 0);
end;

if reg.openkey('System/CurrentControlSet/Control/LSA',true)
then
begin
REG.DeleteValue ('RestrictAnonymous');
reg.WriteInteger('RestrictAnonymous',1);
end;
finally;
reg.CloseKey ;
reg.Free ;
end;
end;
 
沒有錯誤啊?
關注
 
procedure TForm1.Button1Click(Sender: TObject);
var reg:tregistry;
begin
reg:=tregistry.Create ;
try
[red]begin
[/red]
reg.RootKey :=HKEY_LOCAL_MACHINE;
if reg.openkey('System/CurrentControlSet/Services/LanmanServer/Parameters',true)
then
begin
reg.WriteInteger('AutoShareServer', 0);
reg.WriteInteger('AutoShareWks', 0);
end;

if reg.openkey('System/CurrentControlSet/Control/LSA',true)
then
begin
REG.DeleteValue ('RestrictAnonymous');
reg.WriteInteger('RestrictAnonymous',1);
end;
[red]end;
[/red]
finally
begin
reg.CloseKey ;
reg.Free ;
end;
end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var reg:tregistry;
begin
reg:=tregistry.Create ;
//try //不要
reg.RootKey :=HKEY_LOCAL_MACHINE;
if reg.openkey('System/CurrentControlSet/Services/LanmanServer/Parameters',true)
then
begin
reg.WriteInteger('AutoShareServer', 0);
reg.WriteInteger('AutoShareWks', 0);
**********加入***********
reg.CloseKey ;
reg.Free ;
**********加入***********
end;

if reg.openkey('System/CurrentControlSet/Control/LSA',true)
then
begin
REG.DeleteValue ('RestrictAnonymous');
reg.WriteInteger('RestrictAnonymous',1);
**********加入***********
reg.CloseKey ;
reg.Free ;
**********加入***********
end;
//finally;
//不要
//reg.CloseKey ;
每次操作不同的键值都要用
//reg.Free ;
end;
end
 
to jjnb
太粗心了,finally后面多了一个“;”号
 
luckywzy 不要乱说哦[:D],那个分号代表一个空语句:)
 
TO beta
那我就不明白了,如果前面对注册表的操作没有成功,程序一旦挂起,不执行
 reg.CloseKey ;
 reg.Free ;
这两句,岂不是始终锁住注册表了!
 

Similar threads

后退
顶部