检查 VB 中的重新启动挂起状态



我目前正在尝试确定在我正在编写的 VB 程序中应用Microsoft补丁后计算机是否处于"待重启"状态。我有以下几点:

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

但是,这不起作用,并且每次都只返回 Nothing。有什么建议吗?谢谢

通过使用 .本地机器。您已经在HKEY_LOCAL_MACHINE中搜索的部分。尝试使用

regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired", True)

相反。

最新更新