Openremotebasekey异常如何计时,然后在每个循环中转到下一台计算机 [英] Openremotebasekey exceptions how to time and then go to next computer in for each loop

查看:93
本文介绍了Openremotebasekey异常如何计时,然后在每个循环中转到下一台计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个工具(使用Visual Studio 2015 Express - Visual Basic),它将从计算机上的注册表中检查mcafee dat版本和日期,手动输入,在文本文件中输入,或从活动目录中选择。该工具成功返回了970台计算机/笔记本电脑中的714个所有信息。大多数失败要么是因为它们无法在DNS中解析,要么无法ping通,工具会识别这些并成功记录它们。该工具花了15多分钟来检索信息并将其记录在电子表格中。问题在于,在19个失败中,我得到了以下两个错误之一,而那些19个占用了工具的大部分15分钟并记录了所有信息:



1.尝试进行未经授权的操作



2.找不到网络路径



有没有办法使用计时器,以便程序此时将尝试连接到注册表... rk1 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,strComputer,RegistryView.Registry64)然后经过一段时间停止并移动到每个循环中的下一台计算机?我只编写了一年多的编程,我通过试用/错误和谷歌专门学习,所以请耐心等待我,因为我不是一个经验丰富的程序员。这是代码:



我尝试过:



程序运作良好我的目标是通过使它在一段时间内挂起时跳到下一台计算机来改进它。我已经过滤掉了无法在DNS中解析或无法ping通的计算机。



尝试

comsys(主持人)'子程序收集模型名称并登录用户

Dim rk1 As RegistryKey

Dim rk2作为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编号:& mAV

objExcel.Cells(y,6)=DAT Date:& mAD

y = y + 1

Catch ex As Exception

My.Computer.FileSystem.WriteAllText(Dell&\ MGAfeeDATeNumFailed.txt ,sel.Name& - 无法连接。请确保此计算机在网络上,启用了远程管理,并且两台计算机都在运行远程注册表服务。错误消息:& ex.Message& vbCrLf ,True)

结束尝试

I built a tool (with Visual Studio 2015 Express - Visual Basic) that will check the mcafee dat version and date from the registry on computers input either manually, in a text file, or selected from active directory. The tool works it successfully returned all the information for 714 out of 970 computers/laptops. The majority of the failures were either because they could not be resolved in DNS or weren't pingable and the tools identifies those and successfully logs them. It took a little over 15 minutes for the tool to retrieve the information and log it in a spreadsheet. The issue is that on 19 of the failures I got one of the two following errors and those 19 took the majority of the 15 minutes for the tool get and log all the information:

1. Attempted to perform an unauthorized operation

2. The network path was not found

Is there a way of using a timer so that the program will attempt to connect to the registry at this point... rk1 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, strComputer, RegistryView.Registry64) and then after a certain amount of time stop and move to the next computer in the for each loop? I have only been programming for a little over a year and I have learned exclusively through trial/error and google so please have patience with me as I am not a seasoned programmer. Here is the code:

What I have tried:

The program works well my objective here is to improve it by making it skip to the next computer when it hangs for an extended period of time. I have filtered out the computers that can't be resolved in DNS or aren't pingable.

Try
comsys(host)'subroutine to collect model name and logged on user
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, andd that both computers are running the remote registry service. Error message: " & ex.Message & vbCrLf, True)
End Try

推荐答案

这就是我加快速度的方法。它现在可以在3分半钟内处理970台计算机,而不是15到19分钟。





This is how I made it faster. It now processes 970 computers in 3 and a half minutes instead of 15 to 19 minutes.


For Each sel In picker.SelectedObjects
                       Thread.Sleep(5)
                       Try
                           Dim source1 As New CancellationTokenSource
                           Dim token As CancellationToken = source1.Token

                           Dim T20 As Task = Task.Factory.StartNew(Function() getping((sel.Name), token)) 'Function that uses My.Computer.Network.Ping (this ping method resolves the computer in DNS and Ping it) and ping.send (to return IP Address)
                           T20.Wait(60)
                           If T20.Status = TaskStatus.Running Then
                               source1.Cancel()
                               My.Computer.FileSystem.WriteAllText(Dell & "\McAfeeDATeNumFailed.txt", sel.Name & " Ping timed out.  The task was disposed of at " & ex_time & "." & vbCrLf & vbCrLf, True)
                               Continue For
                           End If

                           Dim source2 As New CancellationTokenSource
                           Dim token2 As CancellationToken = source2.Token
                           Dim T21 As Task = Task.Factory.StartNew(Function() comsys((sel.Name), token2)) 'WMI Function
                           T21.Wait(500)
                           If T21.Status = TaskStatus.Running Then
                               source2.Cancel()
                               My.Computer.FileSystem.WriteAllText(Dell & "\McAfeeDATeNumFailed.txt", sel.Name & " RPC error.  The task was disposed of at " & ex_time & "." & vbCrLf & vbCrLf, True)
                           End If

                           Dim source3 As New CancellationTokenSource
                           Dim token3 As CancellationToken = source3.Token
                           Dim T22 As Task = Task.Factory.StartNew(Function() getregvalues((sel.Name), token3)) 'Function that uses RegistryKey.OpenRemoteBaseKey to get remote registry value
                           T22.Wait(600)
                           If T22.Status = TaskStatus.Running Then
                               source3.Cancel()
                               My.Computer.FileSystem.WriteAllText(Dell & "\McAfeeDATeNumFailed.txt", sel.Name & " Error retrieving registry value.  The task was disposed of at " & ex_time & "." & vbCrLf & vbCrLf, True)
                           End If
                           IPAddr = reply.Address.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
                           IPAddr = Nothing
                           reply = Nothing
                           commodel = Nothing
                           comuser = Nothing
                           sel = Nothing
                           Thread.Sleep(5)
                       Catch ex As Exception

                       End Try


这篇关于Openremotebasekey异常如何计时,然后在每个循环中转到下一台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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