Use Screen-Saver Passwords

Use Screen-Saver Passwords

When you write a screen saver in C and the Windows SDK, a static library (SCRNSAVE.lib) allows you to create custom dialogs to change and request the password. But in VB you can’t use this library. If you don’t want to create forms to replace the custom dialogs, use these two undocumented functions:

 Declare Sub PwdChangePassword Lib "mpr.dll" Alias _	"PwdChangePasswordA" (ByVal lpcRegkeyname As String, _	ByVal hWnd As Long, ByVal uiReserved1 As Long, ByVal _	uiReserved2 As Long)Declare Function VerifyScreenSavePwd Lib _	"password.cpl" (ByVal hWnd As Long) As Boolean

PwdChangePassword is in MPR.dll, the Multiple Provider Router. It does all the password management associated with Regkeyname, including popping up a dialog?as a child of hWnd. The two reserved parameters should be zero. VerifyScreen-SavePwd, in password.cpl, pops up a dialog box as a child of hWnd, prompting for the screen saver’s password. If the user gets it wrong, it prints a message saying so and prompts for the password again. If the user presses OK, VerifyScreenSavePwd returns True; if the user presses Cancel, it returns False. These calls?and the DLLs?exist in Windows 95/98 but not in NT because NT handles password management at the system level. Here’s how you can use the PwdChangePassword call:

 Private Sub cmdChange_Click()	PwdChangePassword "SCRSAVE", Me.hWnd, 0, 0End Sub

You must use the string “SCRSAVE” as the first parameter to PwdChangePassword, because it has special meaning and the function fails if another string is passed. Call VerifyScreenSavePwd on detection of mouse or keyboard activity, passing the hWnd the dialog should be owned by. Here’s a simple example of how to test this function:

 Private Sub cmdTest_Click()	Dim bRes As Boolean	bRes = VerifyScreenSavePwd(Me.hWnd)	MsgBox bResEnd Sub
See also - an AI reverse image search platform

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist