万卷书   首页 > 电脑书籍 > 安全在线 > 利用远程注册表加强系统安全
 
 清单 3. 从多台机器中抽取服务包级别

begin
listMachines = ListCreate(STRINGLIST);
ListReadFromFile (listMachines, ";c:\\machineList.txt";);
nResult = ListGetFirstString (listMachines, svMachineName);
while (nResult != END_OF_LIST)
RegDBConnectRegistry (svMahineName , HKEY_LOCAL_MACHINE, 0 );
svKey = ";SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";;
svName = ";CurrentVersion";;
nvType = REGDB_STRING;
RegDBGetKeyValueEx (svKey, svName, nvType, svServicePackVersion, nvSize);
nResult = ListGetNextString (listMachines, svMachineName);
endwhile;
end;

  以上代码将从 machineList.txt 文件中读入一个机器名,连接到它的注册表,进行查询,然后继续移到在文本文件中命名的下一台机器。使用这种方法的优点是通过简单编辑 machineList.txt 文件中的名称,我们能非常容易地在审计过程中添加和除去机器。

  输出信息

  到现在为止,您可能已经注意到当我们执行这些查询时,还没有产生任何输出。所以,现在我们来讨论确定表示输出结果的最好方法。我们团队决定把输出格式化为 XML 文件,因为这样使我们可以浏览检索到的信息,并且允许我们可能开发的任何其它应用程序利用这些数据。清单4 显示了用适当命名的标记生成的 XML 文件。

  清单4. 从多台机器中抽取服务包级别并输出到 XML 文件

; begin
CreateFile (nvFileHandle, ";C:\";, ";Audit.xml";);
WriteLine(nvFileHandle, ";<;?xml version=";1.0";?>;";);
WriteLine(nvFileHandle, ";<;audits&;gt;";);
listMachines = ListCreate(STRINGLIST);
ListReadFromFile (listMachines, ";c:\machineList.txt";);
nResult = ListGetFirstString (listMachines, svMachineName);

while (nResult != END_OF_LIST)
RegDBConnectRegistry (svMachineName , HKEY_LOCAL_MACHINE, 0 );
svKey = ";SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";;
svName = ";CurrentVersion";;
nvType = REGDB_STRING;
RegDBGetKeyValueEx (svKey, svName, nvType, svServicePackVersion, nvSize);
WriteLine(nvFileHandle, ";<;MachineName&;gt;";);
WriteLine(nvFileHandle, ";<;ServicePack&;gt;"; + svCSDVersion+ ";<;/ServicePack&;gt;";
WriteLine(nvFileHandle, ";<;/MachineName&;gt;";);
nResult = ListGetNextString (listMachines, svMachineName);
endwhile;

WriteLine(nvFileHandle, ";<;/audits&;gt;";);
CloseFile(nvFileHandle)
end;
 
上一页 WanJuanShu 下一页