检查VB中的重启挂起状态

时间:2014-02-14 21:11:48

标签: vb.net registry

我正在尝试确定计算机是否在我正在编写的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。有什么建议?谢谢

1 个答案:

答案 0 :(得分:1)

使用.LocalMachine。您已经在HKEY_LOCAL_MACHINE中搜索的部分。尝试使用

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

代替。