我構建了一個工具(使用Visual Studio 2015 Express - Visual Basic),它將從計算機的註冊表中檢查mcafee dat版本和日期可以手動輸入,也可以輸入文本文件或從活動目錄中選擇。該工具可以成功返回970臺電腦/筆記本電腦中的714個信息。大多數故障都是因爲它們無法在DNS中解析或不能ping通,並且工具可識別這些故障併成功記錄它們。該工具花費了15分鐘多一點時間來檢索信息並將其記錄在電子表格中。問題是,在失敗的19,我得到了以下兩個錯誤之一,這19把大部分的15分鐘的工具和日誌中獲取的所有信息:定時器跳過連接到下一臺計算機,爲每個循環使用RegistryKey.OpenRemoteBaseKey遠程連接時
試圖執行未經授權的操作
網絡路徑找不到
是否有使用定時器,使得程序會嘗試連接到註冊表在這一點上... RK1 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine的方式, strComputer,RegistryView.Registry64),然後在一段時間後停止並移動到nex在每個循環中的計算機?我只在一年多的時間裏進行了編程,並且我只通過試驗/錯誤和谷歌學習,所以請耐心等待,因爲我不是一個經驗豐富的程序員。下面是代碼:
該項目工程以及我的目標在這裏是通過使跳到下一臺計算機時,它掛起的長時間來改善它。我篩選出了無法在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
感謝您的回覆。這應該是一個函數,以便它可以返回註冊表值並更新電子表格? –
嗨,我認爲你的代碼很長一段時間是在第二次嘗試聲明。您可以在'endlessLoop'內複製這個內容,替換'您的代碼'評論。然後調用'Main'而不是try語句。嘗試的catch部分可以被複制以抓取endlessLoop的一部分。對不起格式不好,但通過智能手機回答。 – pLurchi
請操縱thrd.join語句。這是等待時間,直到請求以毫秒爲單位中止。 – pLurchi