Check for reboot pending status in VB

帅比萌擦擦* 提交于 2020-01-04 09:27:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!