在Inno Setup中validation用户的密码

我的要求是validation用户input的密码是他login的正确密码。 所以,我写了下面的代码,但总是说“没有login”。 任何帮助?

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; 

Solutions Collecting From Web of "在Inno Setup中validation用户的密码"

起初,您的LogonUser函数原型与其调用一样是错误的。 您不能混合函数原型的数据类型,也不能在函数调用中使用任意值。 你可以用这样的东西代替:

 [Code] #ifdef UNICODE #define AW "W" #else #define AW "A" #endif const LOGON32_LOGON_INTERACTIVE = 2; LOGON32_LOGON_NETWORK = 3; LOGON32_LOGON_BATCH = 4; LOGON32_LOGON_SERVICE = 5; LOGON32_LOGON_UNLOCK = 7; LOGON32_LOGON_NETWORK_CLEARTEXT = 8; LOGON32_LOGON_NEW_CREDENTIALS = 9; LOGON32_PROVIDER_DEFAULT = 0; LOGON32_PROVIDER_WINNT40 = 2; LOGON32_PROVIDER_WINNT50 = 3; ERROR_SUCCESS = 0; ERROR_LOGON_FAILURE = 1326; function LogonUser(lpszUsername, lpszDomain, lpszPassword: string; dwLogonType, dwLogonProvider: DWORD; var phToken: THandle): BOOL; external 'LogonUser{#AW}@advapi32.dll stdcall'; var serverDetailsPage: TInputQueryWizardPage; function TryLogonUser(const Domain, UserName, Password: string; var ErrorCode: Longint): Boolean; var Token: THandle; begin Result := LogonUser(UserName, Domain, Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, Token); ErrorCode := DLLGetLastError; end; procedure InitializeWizard; var UserName: string; begin UserName := AddBackslash(GetEnv('USERDOMAIN')) + GetUserNameString; serverDetailsPage := CreateInputQueryPage(wpWelcome, '', '', 'Please enter following data and click Next.'); serverDetailsPage.Add('IP Address', False); serverDetailsPage.Add('Port Number', False); serverDetailsPage.Add('Domain Name\User Name', False); serverDetailsPage.Add('Password', True); serverDetailsPage.Values[1] := '80'; serverDetailsPage.Values[2] := UserName; end; procedure ParseDomainUserName(const Value: string; var Domain, UserName: string); var DelimPos: Integer; begin DelimPos := Pos('\', Value); if DelimPos = 0 then begin Domain := '.'; UserName := Value; end else begin Domain := Copy(Value, 1, DelimPos - 1); UserName := Copy(Value, DelimPos + 1, MaxInt); end; end; function serverDetailsLogonUser: Boolean; var Domain: string; UserName: string; Password: string; ErrorCode: Longint; begin ParseDomainUserName(serverDetailsPage.Values[2], Domain, UserName); Password := serverDetailsPage.Values[3]; Result := TryLogonUser(Domain, UserName, Password, ErrorCode); case ErrorCode of ERROR_SUCCESS: MsgBox('Logon successful!', mbInformation, MB_OK); ERROR_LOGON_FAILURE: MsgBox('The user name or password is incorrect!', mbError, MB_OK); else MsgBox('Login failed!' + #13#10 + SysErrorMessage(DLLGetLastError), mbError, MB_OK); end; end; function NextButtonClick(CurPageID: Integer): Boolean; begin Result := True; if CurPageID = serverDetailsPage.ID then Result := serverDetailsLogonUser; end;