应用服务器远程动态配置的Delphi编程实现(50)

  • 主题发起人 主题发起人 wpy020327
  • 开始时间 开始时间
W

wpy020327

Unregistered / Unconfirmed
GUEST, unregistred user!
为简单灵活地远程配置分布于各地的QuickBurro应用服务器,近日完成了一个远程注册表访问插件的编写,与原来的远程文件管理插件、远程桌面监控等插件一起,为应用程序的特殊应用编程及维护管理创造了很好的条件。下面是进行远程注册表访问的示例代码,可以看出,程序编写很轻松://// 创建一个子键...procedure TForm1.Button1Click(Sender: TObject);
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.CreateKey('Software/JopherStudio') then
memo1.Lines.Add('HKEY_LOCAL_MACHINE下创建子键“Software/JopherStudio”成功喽!') else
memo1.Lines.Add('HKEY_LOCAL_MACHINE下创建子键“Software/JopherStudio”失败!');
end;
//// 删除一个子键...procedure TForm1.Button2Click(Sender: TObject);
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.DeleteKey('Software/JopherStudio') then
memo1.Lines.Add('HKEY_LOCAL_MACHINE下删除子键“Software/JopherStudio”成功喽!') else
memo1.Lines.Add('HKEY_LOCAL_MACHINE下删除子键“Software/JopherStudio”失败!');
end;
//// 写入一个值...procedure TForm1.Button14Click(Sender: TObject);
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.WriteString('Software/JopherStudio','Test','哈哈哈') then
memo1.Lines.Add('HKEY_LOCAL_MACHINE/Software/JopherStudio下写入值“test”成功喽!') else
memo1.Lines.Add('HKEY_LOCAL_MACHINE/Software/JopherStudio下写入值“test”失败!');
end;
//// 删除一个值...procedure TForm1.Button3Click(Sender: TObject);
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.DeleteValue('Software/JopherStudio','Test') then
memo1.Lines.Add('HKEY_LOCAL_MACHINE/Software/JopherStudio下删除值“test”成功喽!') else
memo1.Lines.Add('HKEY_LOCAL_MACHINE/Software/JopherStudio下删除值“test”失败!');
end;
//// 取键值数据大小...procedure TForm1.Button4Click(Sender: TObject);var j: integer;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
j:=RpcRemoteRegistry1.GetDataSize('Software/JopherStudio','Test');
memo1.Lines.Add('HKEY_LOCAL_MACHINE/Software/JopherStudio下的键值“test”的大小='+inttostr(j));
end;
//// 取键值数据类型...procedure TForm1.Button5Click(Sender: TObject);var j: integer;
tmpstr: string;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
j:=RpcRemoteRegistry1.GetDataType('Software/JopherStudio','Test');
case j of 1: tmpstr:='rdUnknown';
2: tmpstr:='rdString';
3: tmpstr:='rdExpandString';
4: tmpstr:='rdInteger';
5: tmpstr:='rdBinary';
else
tmpstr:='未知!';
end;
memo1.Lines.Add('HKEY_LOCAL_MACHINE/Software/JopherStudio下的键值“test”的类型='+tmpstr);
end;
//// 取子键信息...procedure TForm1.Button6Click(Sender: TObject);var KeyInfo: TRegkeyinfo;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.GetKeyInfo('Software/JopherStudio',KeyInfo) then
begin
memo1.Lines.Add('取HKEY_LOCAL_MACHINE/Software/JopherStudio下的子键信息成功喽!');
memo1.Lines.Add('NumSubKeys='+inttostr(KeyInfo.NumSubKeys));
memo1.Lines.Add('maxsubkeylen='+inttostr(KeyInfo.maxsubkeylen));
memo1.Lines.Add('numvalues='+inttostr(KeyInfo.numvalues));
memo1.Lines.Add('maxvaluelen='+inttostr(KeyInfo.maxvaluelen));
memo1.Lines.Add('MaxDataLen='+inttostr(KeyInfo.MaxDataLen));
memo1.Lines.Add('Filetime='+formatdatetime('yyyy-mm-dd hh:nn:ss',KeyInfo.Filetime));
end else
memo1.Lines.Add('取HKEY_LOCAL_MACHINE/Software/JopherStudio下的子键信息失败!');
end;
//// 取子键名称列表...procedure TForm1.Button8Click(Sender: TObject);var tmpstr: string;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.GetKeyNames('Software',tmpstr) then
begin
memo1.Lines.Add('取HKEY_LOCAL_MACHINE/Software下的子键名称列表成功喽!');
memo1.Lines.Add(tmpstr);
end else
memo1.Lines.Add('取HKEY_LOCAL_MACHINE/Software下的子键名称列表失败!');
end;
//// 取键值名称列表...procedure TForm1.Button9Click(Sender: TObject);var tmpstr: string;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.GetValueNames('Software/Microsoft/Windows/CurrentVersion/Run',tmpstr) then
begin
memo1.Lines.Add('取HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Run下的键值名称列表成功喽!');
memo1.Lines.Add(tmpstr);
end else
memo1.Lines.Add('取HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Run下的键值名称列表失败!');
end;
//// 判断是否有下属子键...procedure TForm1.Button10Click(Sender: TObject);var ok: boolean;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.HasSubKeys('Software/JopherStudio',ok) then
begin
memo1.Lines.Add('判定HKEY_LOCAL_MACHINE/Software/JopherStudio下是否存在子键成功喽!');
if ok then
memo1.Lines.Add('存在子键!') else
memo1.Lines.Add('不存在子键!');
end else
memo1.Lines.Add('判定HKEY_LOCAL_MACHINE/Software/JopherStudio下是否存在子键失败!');
end;
//// 判定某个键存在否...procedure TForm1.Button11Click(Sender: TObject);var ok: boolean;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.KeyExists('Software/JopherStudio',ok) then
begin
memo1.Lines.Add('判定是否存在HKEY_LOCAL_MACHINE/Software/JopherStudio键成功喽!');
if ok then
memo1.Lines.Add('该键存在!') else
memo1.Lines.Add('该键不存在!');
end else
memo1.Lines.Add('判定是否存在HKEY_LOCAL_MACHINE/Software/JopherStudio键失败!');
end;
//// 将一个键移动到另一位置...procedure TForm1.Button12Click(Sender: TObject);
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.MoveKey('Software/JopherStudio','Hardware/JopherStudio',false) then
memo1.Lines.Add('复制HKEY_LOCAL_MACHINE/Software/JopherStudio到HKEY_LOCAL_MACHINE/Hardware/JopherStudio成功喽!') else
memo1.Lines.Add('复制HKEY_LOCAL_MACHINE/Software/JopherStudio到HKEY_LOCAL_MACHINE/Hardware/JopherStudio失败!');
end;
//// 读键值...procedure TForm1.Button13Click(Sender: TObject);var tmpstr: string;
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
tmpstr:=RpcRemoteRegistry1.ReadString('Software/JopherStudio','Test');
memo1.Lines.Add('HKEY_LOCAL_MACHINE/Software/JopherStudio下的键值Test的值='+tmpstr);
end;
//// 导出到文件...procedure TForm1.Button16Click(Sender: TObject);
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.SaveToFile('Software/JopherStudio','c:/Test.reg') then
memo1.Lines.Add('将HKEY_LOCAL_MACHINE/Software/JopherStudio导出到文件成功喽!') else
memo1.Lines.Add('将HKEY_LOCAL_MACHINE/Software/JopherStudio导出到文件失败!');
end;
//// 从文件导入到注册表...procedure TForm1.Button15Click(Sender: TObject);
begin
RpcRemoteRegistry1.TargetNodeId:=QBConnection1.NodeId;
RpcRemoteRegistry1.RootKey:='HKEY_LOCAL_MACHINE';
if RpcRemoteRegistry1.LoadFromFile('c:/Test.reg') then
memo1.Lines.Add('将c:/Test.reg导入到注册表成功喽!') else
memo1.Lines.Add('将c:/Test.reg导入到注册表失败!');
end;
 
后退
顶部