当我运行以下代码行时,我的屏幕保护程序的密码保护未启用。我还检查了用于控制密码保护的注册表项,它也没有被切换。
If SystemParametersInfo(SPI_SETSCREENSAVESECURE, 1, nullVar, SPIF_SENDWININICHANGE) = 0 Then
Throw New WindowsDotHException(ErrorToString(Err.LastDllError()) & " (Error number " & Err.LastDllError & ")")
End If
语境:
WindosDotHException 是我处理来自 SystemParametersInfo 的错误代码的方法。
' Signatures for unmanaged calls
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function SystemParametersInfo(uAction As Integer, uParam As Integer, ByRef lpvParam As Integer, flags As Integer) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function SystemParametersInfo(uAction As Integer, uParam As Integer, ByRef lpvParam As Boolean, flags As Integer) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function PostMessage(hWnd As IntPtr, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function OpenDesktop(hDesktop As String, Flags As Integer, Inherit As Boolean, DesiredAccess As UInteger) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function CloseDesktop(hDesktop As IntPtr) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function EnumDesktopWindows(hDesktop As IntPtr, callback As EnumDesktopWindowsProc, lParam As IntPtr) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function IsWindowVisible(hWnd As IntPtr) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function GetForegroundWindow() As IntPtr
End Function
' Callbacks
Private Delegate Function EnumDesktopWindowsProc(hDesktop As IntPtr, lParam As IntPtr) As Boolean
' Constants
Private Const SPI_GETSCREENSAVERACTIVE As Integer = 16
Private Const SPI_SETSCREENSAVERACTIVE As Integer = 17
Private Const SPI_GETSCREENSAVERTIMEOUT As Integer = 14
Private Const SPI_SETSCREENSAVERTIMEOUT As Integer = 15
Private Const SPI_GETSCREENSAVERRUNNING As Integer = 114
Private Const SPIF_SENDWININICHANGE As Integer = 2
Private Const SPI_SETSCREENSAVESECURE As Integer = 119
Private Const DESKTOP_WRITEOBJECTS As UInteger = &H80
Private Const DESKTOP_READOBJECTS As UInteger = &H1
Private Const WM_CLOSE As Integer = 16
操作系统:Windows 7 32位版本
语言:VB.Net
我尝试过的事情:
- 重新启动计算机
- 运行代码后注销并重新登录
如何在 Windows 7 中启用密码保护?