给大家贴一段退出屏保时的密码验证过程:
procedure GetPassword;
var
MyMod: THandle;
PwdFunc: function(Parent: THandle): Boolean; stdcall;
SysDir: string;
NewLen: Integer;
MyReg: TRegistry;
OkToClose: Boolean;
begin
if (SSMode <> ssRun) then
begin
Close;
Exit;
end;
IgnoreCount := 5;
OkToClose := False;
MyReg := TRegistry.Create;
try
MyReg.RootKey := HKEY_CURRENT_USER;
if MyReg.OpenKey('Control Panel/Desktop', False) then
begin
try
try
ShowCursor(True);
if MyReg.ReadInteger('ScreenSaveUsePassword') <> 0 then
begin
SetLength(SysDir, MAX_PATH);
NewLen := GetSystemDirectory(PChar(SysDir), MAX_PATH);
SetLength(SysDir, NewLen);
if (Length(SysDir) > 0) and (SysDir[Length(SysDir)] <> '/') then
SysDir := SysDir + '/';
MyMod := LoadLibrary(PChar(SysDir + 'PASSWORD.CPL'));
if MyMod = 0 then
OkToClose := True
else
begin
PwdFunc := GetProcAddress(MyMod, 'VerifyScreenSavePwd');
if PwdFunc(Handle) then
OkToClose := True;
FreeLibrary(MyMod);
end;
end
else
OkToClose := True;
finally
ShowCursor(False);
end;
except
OkToClose := True;
end;
end
else
OkToClose := True;
finally
MyReg.Free;
end;
if OkToClose then
Close;
end;