Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Advanced
Feb 24, 2000

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, 0
End 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 bRes
End Sub
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap