如何在Inno Setup中访问远程计算机的注册表 [英] How to access registry of a remote machine in Inno Setup

查看:80
本文介绍了如何在Inno Setup中访问远程计算机的注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Inno Setup安装程序,可用于更新客户站点上的计算机.通常有两台计算机,但有时三台或更多.所有人都联网了,而只有一个人是无头的.

I have Inno Setup installers that I use to update computers at customer sites. Generally there are two computers, but sometimes three or more. All are networked, and exactly one is headless.

在所有带头的工作站(如果与无头计算机相反)上运行安装程序相对容易,因此可以运行与这些计算机关联的所有任务.在无头工作站上还需要执行一些任务.通常,这些任务是快速,简单的任务(复制小文件并重新启动服务),可以多次运行.

It is relatively easy to run the installer on all the headed (if that's the opposite of headless?) workstations, thus running all tasks associated with those computers. There are also tasks that need to be performed on the headless workstation. Generally, these are quick, simple tasks (copying small files and restarting services) that can be run multiple times.

但是,有时我会遇到耗时的任务,这些任务最好只执行一次,例如需要重新启动的任务.在这种情况下,我需要确定是否安装了旧版本的UltraVNC,而我所知道的最好方法是查询无头工作站上的注册表.不幸的是,RegQueryStringValue不提供用于查询远程计算机上的注册表的选项.

Occasionally, however, I encounter time consuming tasks that are best performed exactly once, such as tasks that require reboots. In this particular case, I need to determine if I have a broken version of UltraVNC installed, and the best way I know of is to query the registry on the headless workstation. Unfortunately, RegQueryStringValue does not supply options for querying registries on remote machines.

如何做到这一点?

推荐答案

此问题由于两件事而变得复杂:

This issue is complicated by two things:

  1. UltraVNC将其自身安装在64位Windows上的注册表的64位视图中,因此我们需要查询这两个视图,并且
  2. 默认情况下,RemoteRegistry不在Windows Vista和更高版本上运行.

这是我想出的:

function RegConnectRegistry(machineName: String; hKeyRoot:Integer; var phKey: Integer): integer;
  external 'RegConnectRegistryA@Advapi32.dll';
function RegOpenKeyEx(hKeyRoot:Integer; subkey:string; reserved, access:integer; var phKey: Integer): integer;
  external 'RegOpenKeyExA@Advapi32.dll';
function RegQueryValueEx(hKey:Integer; value: String; reserved: integer; var pType: integer; data: string; var pDataLen:integer): integer;
  external 'RegQueryValueExA@Advapi32.dll';
function RegCloseKey(hKey:Integer): integer;
  external 'RegCloseKey@Advapi32.dll';

然后,调用函数相对简单.为了简洁起见,大多数错误处理已被省略.同样,不尝试读取非REG_SZ值.

Then, calling the functions is relatively straightforward. Most error handling has been omitted for conciseness. Also, no attempt is made to read non-REG_SZ values.

<target>是目标,无论是按名称还是按IP地址. <key><value>是要查询的远程键和值.

<target> is the target, either by name or by IP address. <key> and <value> are the remote key and value to query.

procedure CheckRemoteVNC();
var
  HKRM, key: Integer;
  data: string;
  dwType, dataLen, retVal: Integer;
begin
  data := '12345678901234567890'; { Padding. Digits so I can easily count how long it is. }
  dataLen := 20
  { Make sure the Remote Registry service is running }
  Exec('sc', ExpandConstant('\\<target> start RemoteRegistry'), '', SW_HIDE, ewWaitUntilTerminated, retVal)
  RegConnectRegistry('<target>', HKEY_LOCAL_MACHINE, HKRM)
  if RegOpenKeyEx(HKRM, '<key>', 0, 1 {KEY_QUERY_VALUE}, key) = 2 {Bad registry entry} then
    { Try the 64-bit view. }
    retVal := RegOpenKeyEx(HKRM, '<key>', 0, 257 {0x101 == KEY_WOW64_64KEY | KEY_QUERY_VALUE}, key)
  RegQueryValueEx(Key, '<value>', 0, dwType, data, dataLen)
  data := Copy(data, 0, dataLen-1)

  { Deal with the data appropriately. }

  if key <> 0 then RegCloseKey(key)
  if HKRM <> 0 then RegCloseKey(HKRM)
end;

请参见 Microsoft的文档有关这些功能的详细信息.

这篇关于如何在Inno Setup中访问远程计算机的注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆