一开始,你的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;