VA单点登录脚步实施实例之用友U8_11.0
于被实施程序分为多个不同的版本,自动登录脚本会有小范围修正.程序: 用友U8
版本:11.0
uses uApp,Sysutils,Windows, Dialogs;
function GetLang(const InValue:string):string;
begin
Result := '';
if InValue = 'CHT' then Result := '{DOWN}'
else if InValue = 'ENU' then Result := '{DOWN}{DOWN}';
end;
function GetAccount(const InValue:string):string;
var i :integer;
begin
Result := '';
for i := 1 to StrToInt(InValue) - 1 do begin
Result := Result + '{DOWN}';
end;
end;
procedure ErrorLog(const ErrorMsg:string);
begin
App.DebugLog(ErrorMsg);
end;
function InputText(const aMode: Integer; const aTargetWin: DWORD; const aText: string): Boolean;
var
s: string;
begin
Result := True;
s := aText;
Case aMode of
1 : begin
uApp.SetTextByWM_SetText(aTargetWin, s);
end;
2 : begin
uApp.SelectAllByEM_SETSEL(aTargetWin); //Select All
uApp.SetTextByClipBoard(aTargetWin, s);
end;
3 : begin
uApp.ClearTextByWM_CharAndKey(aTargetWin, 20);
uApp.SetTextByWM_Char(aTargetWin, s);
end;
4 : begin
s := uApp.Str2Macrostr(s);
uApp.SetFocusByAttachThread(aTargetWin, 5000);
uApp.SetTextByKeyEvent(aTargetWin, s);
end;
else
Result := false;
end;
end;
procedure SetComboboxIndexByKB(const aHandle : DWORD;const aIndex : Integer);
var
i,j,curIndex : Integer;
begin
for i := 1 to 3 Do begin
curIndex := Windows.SendMessage(aHandle,messages.CB_GETCURSEL,0,0);
if aIndex > curIndex then begin
for j := 1 to (aIndex-curIndex) Do begin
Windows.PostMessage(aHandle,Messages.WM_KEYDOWN,windows.VK_DOWN,0);
Windows.PostMessage(aHandle,Messages.WM_KEYUP,windows.VK_DOWN,0);
Windows.Sleep(10) ;
end;
end else if aIndex < curIndex then begin
for j := 1 to (curIndex-aIndex) Do begin
Windows.PostMessage(aHandle,Messages.WM_KEYDOWN,windows.VK_UP,0);
Windows.PostMessage(aHandle,Messages.WM_KEYUP,windows.VK_UP,0);
Windows.Sleep(10) ;
end;
end
else begin
Exit;
end;
Windows.Sleep(666);
end;
end;
function ChildWindowCount : Integer;
var iCount : Integer;
begin
Result := 0; iCount := 0;
while true Do begin
if iCount > 5 then Exit;
Result := uApp.GetChildWinCount(Alp.TopWinInfo.WinHandle,true);
if (Result < Alp.TopWinInfo.ChildWinCount) then begin
iCount := iCount + 1;
Windows.Sleep(50);
continue;
end
else begin
Exit;
end;
end;
end;
function ChildWinCountIs19(const WaiteTimeOut:DWORD):Boolean;
var
iWinCount,i : Integer;
FirstTick: LongWord;
begin
Result := False;
FirstTick := windows.GetTickCount;
iWinCount := ChildWindowCount;
while True do begin
if ((windows.GetTickCount - FirstTick) > WaiteTimeOut) then Break;
if iWinCount < Alp.TopWinInfo.ChildWinCount then Sleep(200)
else beginResult := True; Break; end;
iWinCount := ChildWindowCount;
end;
end;
function InitEditorParams : Boolean;
begin
Result := false;
//----------Username Window
ALP.Editor_Username.WinIndex := 17;
ALP.Editor_Username.InputMode := 1;
ALP.Editor_Username.WinHandle := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.Editor_Username.WinIndex, True);
//----------Password Window
ALP.Editor_Password.WinIndex := 7;
ALP.Editor_Password.InputMode := 1;
ALP.Editor_Password.WinHandle := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.Editor_Password.WinIndex, True);
//--------Custom Widnow
ALP.Editor.WinIndex := 35;//Login Server Name
ALP.Editor.InputMode := 1;
ALP.Editor.WinHandle := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.Editor.WinIndex, True);
ALP.Editor.WinIndex := 20; //Account
ALP.Editor.WinHandle := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.Editor.WinIndex, True);
ALP.Editor.WinIndex := 1; //Language
ALP.Editor.WinHandle := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.Editor.WinIndex, True);
ALP.Editor.WinIndex := 12; //OpDate
ALP.Editor.InputMode := 1;
ALP.Editor.WinHandle := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.Editor.WinIndex, True);
//----------Click LoginButton
ALP.LoginButton.WinIndex := 42;
if ALP.LoginButton.WinIndex = 0 then
ALP.LoginButton.WinHandle := ALP.TopWinInfo.WinHandle
else if ALP.LoginButton.WinIndex > 0 then
ALP.LoginButton.WinHandle := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.LoginButton.WinIndex, True);
ALP.LoginButton.ClickMode := 1;
Result := True;
end;
procedure AutoLogin;
type TMouseButton = (mbLeft, mbRight, mbMiddle);
var
htop, hchild: DWORD;
b: boolean;
i,j,k: Integer;
s, s1,s2,s3,s4,s5, s6, sDel, sEnter : string;
begin
if uApp.CAppHelperVersion < 110126 then begin
ErrorLog('Current Script Engine Is Low!');
Exit;
end;
if ALP = nil then begin
ErrorLog('Current Script Engine Is Low!' );
Exit;
end;
//--------- Set Autologin Params
//----------Find Top Window
ALP.TopWinInfo.WinClass := 'WindowsForms10.Window.8.app*';//'WindowsForms10.Window.8.app.0.2e0c681';
ALP.TopWinInfo.WinTitle := '登 錄|登录|Login'; //*AB*,*AB,AB*,AB,AB|cd*|*Ef*
Alp.TopWinInfo.FindTimeout := 5000;
ALP.TopWinInfo.ChildWinCount := 43;
//----------1 Wait Target Application Idle
ALP.TopWinInfo.IdleTimeout :=5000;
//-----------Find Top Window
htop := uApp.FindMatchWinWithTimeout(ALP.ProcessID, ALP.TopWinInfo.WinClass,ALP.TopWinInfo.WinTitle,Alp.TopWinInfo.FindTimeout);
if (htop <= 0) then begin
ErrorLog('Not Find Top Window!');
Exit;
end;
ALP.TopWinInfo.WinHandle := htop;
//-----------1 Wait Target Application Idle
b := uApp.CheckWindowProcessIsIdle(htop, ALP.TopWinInfo.IdleTimeout);
if b = false then begin
s := Sysutils.IntToStr(ALP.TopWinInfo.IdleTimeout);
ErrorLog('Target Application Wait '+s+'s,Still Not Idle!');
Exit;
end;
//------Login ServerName
ALP.Editor.WinIndex := 35;
hchild := uApp.FindWinByThCi(ALP.TopWinInfo.WinHandle, ALP.Editor.WinIndex, True);
if hchild <= 0 then begin
s := Sysutils.IntToStr(ALP.Editor.WinIndex);
ErrorLog('Not Find Login ServerName Window Index:'+s+' !');
Exit;
end;
//-----输入信息
uApp.SetFocusByAttachThread(htop, 5000);
Sleep(200);
uApp.SetFocusByAttachThread(htop, 5000);
Sleep(200);
s1 := ALP.Editor.Value + '{TAB}';
s2 := ALP.Editor_Username.Value + '{TAB}';
s3 := ALP.Editor_Password.Value + '{TAB}';
s4 := '{UP}{UP}{UP}' + GetAccount(ALP.Editor.Value) + '{TAB}';
s5 := '{UP}{UP}{UP}' + GetLang(ALP.Editor.Value) + '{TAB}';
s6 := ALP.Editor.Value + '{ENTER}';
uApp.SetTextByKeyEvent(htop, '{TAB}');Sleep(100);
uApp.SetTextByKeyEvent(htop, '{TAB}');Sleep(100);
uApp.SetTextByKeyEvent(htop, '{TAB}');Sleep(100);
uApp.SetTextByKeyEvent(htop, '{TAB}');Sleep(100);
uApp.SetTextByKeyEvent(htop, '{TAB}');Sleep(100);
//ServerName
uApp.SetTextByKeyEvent(htop, s1);
Sleep(500);
//UserName
uApp.SetTextByKeyEvent(htop, s2);
Sleep(500);
//Password
uApp.SetTextByKeyEvent(htop, s3);
Sleep(500);
//Account
uApp.SetTextByKeyEvent(htop, s4);
Sleep(500);
//Language
uApp.SetTextByKeyEvent(htop, s5);
Sleep(500);
//OpDate
uApp.SetTextByKeyEvent(htop, s6);
ErrorLog('Do Autologin OK') ;
end;
begin
try
AutoLogin;
except
ErrorLog('Do Autologin Except!') ;
end;
end.
页:
[1]