What about winexec?

Source: Internet
Author: User
What about winexec? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061114224727232.html
Below is Program Call program B. The logon page of program B is displayed. Enter the user name and password to log on to program B automatically.

Procedure tform1.image1click (Sender: tobject );
VaR
Fhwnd: thandle;
T1hwnd: thandle;
T2hwnd: thandle;
Bhwnd: thandle;
Begin
Winexec (pchar ('C: \ B .exe '), 0 );
// Why does the login interface pop up when run Runs to wait for the user to respond?
Why not directly run the following automatic username and password login operation ??
// But the strange thing is that you can execute it step by step and log on automatically !!
Fhwnd: = findwindow (nil, 'System logins ');
If fhwnd> 0 then
Begin
T1hwnd: = find1_wex (fhwnd, 0, 'tcombobox', nil );
T2hwnd: = find1_wex (fhwnd, 0, 'tedit ', nil );
Bhwnd: = find1_wex (fhwnd, 0, 'tbitbtn ', nil );

If t1hwnd> 0 then
Sendmessage (t1hwnd, wm_settext, 0, INTEGER (pchar (User )));
If t2hwnd> 0 then
Sendmessage (t2hwnd, wm_settext, 0, INTEGER (pchar (PWD )));
If bhwnd> 0 then
Sendmessage (bhwnd, bm_click, 0, 0 );
End;
End;

Please kindly advise!

because it takes some time (even dozens of microseconds) to start a process, the Code execution speed is very fast, at this time, the code for searching the window may have been executed. Therefore, after winexec (pchar ('C: \ B .exe '), 0), it will be better to delay some time, such as about 1 second. Latency:
var
dwtickcount: DWORD;
begin
winexec ('C: \ B .exe ', 0 );
// 1 second delay
dwtickcount: = gettickcount;
while gettickcount () application. processmessages;
// continue to the next step
fhwnd: = findwindow (nil, 'System logins ');
...
end;

I hit your lungs

That sound great!

Very good
I call a common two-tier program. The problem does not exist.
The preceding problem occurs when a three-tier program is called.
Solution after 1 second delay
Thank you! Thank you very much for your advice!

Good

Top

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.