Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 29-Jul-16 8:41am

1 solution

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


VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900