问题
I'm currently trying to determine if a computer is in a "pending reboot" status after applying Microsoft patches in a VB program I'm writing. I have the following:
Private Sub DoesKeyExist()
Dim regKey As Microsoft.Win32.RegistryKey
regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired", True)
If regKey Is Nothing Then
MsgBox("No reboot pending.")
Else
MsgBox("Reboot is pending")
End If
End Sub
This isn't working, however, and just returns Nothing each time. Any suggestions? Thanks
回答1:
By using the .LocalMachine. part you are already searching in HKEY_LOCAL_MACHINE. Try to use
regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired", True)
instead.
来源:https://stackoverflow.com/questions/21789594/check-for-reboot-pending-status-in-vb