我的要求是验证用户输入的密码是他登录时使用的正确密码。所以,我写了下面的代码,但它总是说“未登录”。有什么帮助吗?
var
DomainName,UserName,BackwardSlashString,DomainUserName : String;
ServerDetailsInputPage : TInputQueryWizardPage;
hToken, LoginOk : INTEGER;
function LogonUser(lpszUsername,lpszDomain,lpszPassword: string;
dwLogonType,dwLogonProvider: INTEGER; var hToken: INTEGER): INTEGER;
external 'LogonUserA@advapi32.dll stdcall';
procedure InitializeWizard();
begin
DomainName:= ExpandConstant(GetEnv('USERDOMAIN'));
UserName := ExpandConstant( +GetUserNameString);
BackwardSlashString := '\'
DomainUserName := DomainName + BackwardSlashString + UserName;
ServerDetailsInputPage :=
CreateInputQueryPage(wpWelcome,'','','Please enter following data and click Next.');
ServerDetailsInputPage.Add('IP Address',False);
ServerDetailsInputPage.Add('Port Number',False);
ServerDetailsInputPage.Add('Domain Name\User Name',False);
ServerDetailsInputPage.Add('Password',True);
ServerDetailsInputPage.Values[1] := '80';
ServerDetailsInputPage.Values[2] := DomainUserName;
end;
function RunAsUser(): BOOLEAN;
var
Passwd : String;
begin
DomainName := ExpandConstant(GetEnv('USERDOMAIN'));
UserName := ExpandConstant( +GetUserNameString);
Passwd := ServerDetailsInputPage.Values[3];
LoginOk := LogonUser(UserName,DomainName,Passwd,1,0,hToken);
if (not (LoginOk=0)) then
begin
MsgBox('successfully logged-in', mbInformation, MB_OK);
Result := true;
end
else if (LoginOk=0) then
begin
MsgBox('Not logged-in', mbInformation, MB_OK);
Result := false;
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if CurPageID = ServerDetailsInputPage.ID then
begin
if not RunAsUser then
begin
MsgBox('Please enter correct Password!', mbError, MB_OK);
Result:=False;
end;
end;
end;
function InitializeSetup(): Boolean;
var
PrevInstallPath : String;
ResultCode : Integer;
FXStopStatus : Boolean;
begin
Result:=True;
end;