我构建了一个工具(使用 Visual Studio 2015 Express - Visual Basic),它将检查计算机上注册表中的 mcafee dat 版本和日期,手动输入、文本文件输入或从活动目录中选择输入。该工具成功地返回了 970 台计算机/笔记本电脑中 714 台的所有信息。大多数失败要么是因为它们无法在 DNS 中解析,要么是无法 ping 通,而这些工具会识别并成功记录它们。该工具花费了 15 分钟多一点的时间来检索信息并将其记录在电子表格中。问题是,在 19 次失败中,我遇到了以下两个错误之一,而这 19 次错误花费了 15 分钟的大部分时间来获取并记录所有信息:
试图执行未经授权的操作
找不到网络路径
有没有一种使用计时器的方法,以便程序此时将尝试连接到注册表... rk1 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, strComputer, RegistryView.Registry64) 然后在一段时间后停止并移动到 for each 循环中的下一台计算机?我只编程了一年多一点,我完全是通过试错和谷歌学习的,所以请耐心等待我,因为我不是一个经验丰富的程序员。这是代码:
该程序运行良好,我的目标是通过使其在长时间挂起时跳到下一台计算机来改进它。我已过滤掉无法在 DNS 中解析或无法 ping 的计算机。
For Each sel In picker.SelectedObjects
Try
If HostIsResolvable(sel.Name) Then
Try
reply = ping.Send(sel.Name, 1)
If reply.Status = IPStatus.Success Then
IPAddr = reply.Address.ToString()
Try
comsys(sel.Name)
Dim rk1 As RegistryKey
Dim rk2 As RegistryKey
rk1 = RegistryKey.OpenRemoteBaseKey
(RegistryHive.LocalMachine, sel.Name,
RegistryView.Registry64)
rk2 = rk1.OpenSubKey
("SOFTWARE\Wow6432Node\McAfee\AVEngine")
mAV = rk2.GetValue("AVDatVersion").ToString
mAD = rk2.GetValue("AVDatDate").ToString
objExcel.Cells(y, 1) = sel.Name
objExcel.Cells(y, 2) = IPAddr
objExcel.Cells(y, 3) = commodel
objExcel.Cells(y, 4) = comuser
objExcel.Cells(y, 5) = "DAT Version Number: " & mAV
objExcel.Cells(y, 6) = "DAT Date: " & mAD
y = y + 1
Catch ex As Exception
My.Computer.FileSystem.WriteAllText(Dell
& "\McAfeeDATeNumFailed.txt", sel.Name & "-Unable to
connect. Make sure this computer is on the network,
has remote administration enabled, and that both
computers are running the remote registry service.
Error message: " & ex.Message & vbCrLf, True)
End Try
Else
My.Computer.FileSystem.WriteAllText(Dell
& "\McAfeeDATeNumFailed.txt", sel.Name & " is not
pingable! " & vbCrLf, True)
End If
Catch ex As Exception
My.Computer.FileSystem.WriteAllText(Dell
& "\McAfeeDATeNumFailed.txt", sel.Name & "Ping error:
Unable to connect. Make sure this computer is on the
network, has remote administration enabled, and that
both computers are running the remote registry
service. Error message: " & ex.Message & vbCrLf, True)
End Try
Else
My.Computer.FileSystem.WriteAllText(Dell
& "\McAfeeDATeNumFailed.txt", sel.Name & " could not be
resolved in DNS! " & vbCrLf, True)
End If
Catch ex As Exception
My.Computer.FileSystem.WriteAllText(Dell
& "\McAfeeDATeNumFailed.txt", sel.Name & "DNS error: Unable to
connect. Make sure this computer is on the network, has remote
administration enabled, andd that both computers are running the
remote registry service. Error message: " & ex.Message &
vbCrLf, True)
End Try
sel = Nothing
Next