WaitForSingleObject可能已进入等待結束 状态 程序没结束就没法执行下一句
你把TerminateProcess(execinfo.hProcess,h); 写到另一个buttun里试式
你把TerminateProcess(execinfo.hProcess,h); 写到另一个buttun里试式
解决方案 »
- WebBrowser使用乱码问题。
- 请问只有线程ID或句柄,能否判断出该线程是否还在使用呢?
- DELPHI和网络结合的一个问题?我想问问怎么才能知道对方是从哪个网站的链接点到我的网站的?
- 设置断点调试dll时,断点不起作用!这是为什么啊??
- 能给小弟一些关于进销存软件的图标吗
- spcomm怎么返回的AT指令的值不对啊??急,急………………
- 不知啥原因?请高手指教
- 请教:QQ里点击“聊天记录”后在原窗口下拉出一“聊天记录”窗口,是怎么做到的?
- 关于adoquery控件的几个问题?
- 所见即所得:按照IMAGE(stretch:=True)显示的图片大小进行保存。
- 如何让一个窗体在屏幕上的位置固定不动?急
- 这两天没事干。我搞了两个网址。http://borlandsoft.yeah.net 、 http://borlandsoft.126.com 、http://borlandsoft.home.chinaren.com/
execinfo: TSHELLEXECUTEINFO;
dwRet, dwTicks: LongWord;
begin
FillChar(execinfo,SizeOf(execinfo),0);
execinfo.cbSize:=sizeof(execinfo);
execinfo.lpVerb:='Open';
execinfo.lpFile:='cn_server.exe';
execinfo.fMask:=SEE_MASK_NOCLOSEPROCESS;
execinfo.nShow:=SW_SHOWDEFAULT;
if ShellExecuteEx(@execinfo) then
begin
ShowMessage( Format('execinfo.hProcess=%d', [execinfo.hProcess]) ); dwTicks := GetTickCount;
repeat
if GetExitCodeProcess(execinfo.hProcess, dwRet) and (STILL_ACTIVE<>dwRet) then
begin // terminated
ShowMessage( 'Returned!' );
Break;
end; if GetTickCount-dwTicks>3000 then // Time out
begin
if Application.MessageBox( 'kill the process?', 'Timed out', MB_ICONQUESTION or MB_OKCancel)=IDCancel then
dwTicks := GetTickCount // recount
else
begin
TerminateProcess(execinfo.hProcess, 255);
ShowMessage( 'Killed!' );
Break;
end;
end; Application.ProcessMessages; // 不要让应用程序象死了一样,:)
until False; // dead loop end
else
ShowMessage( 'Can not run it!' );
end;
var execinfo: TSHELLEXECUTEINFO;dwRet, dwTicks,FileHandle:LongWord;fn:string;
begin
IF not FILEEXISTS('ser_comp.txt') THEN
begin
FillChar(execinfo,SizeOf(execinfo),0);
execinfo.cbSize:=sizeof(execinfo);
execinfo.lpVerb:='Open';
execinfo.lpFile:='cn_server.exe';
execinfo.fMask:=SEE_MASK_NOCLOSEPROCESS;
execinfo.nShow:=SW_SHOWDEFAULT;
if ShellExecuteEx(@execinfo) then
begin
//ShowMessage( Format('execinfo.hProcess=%d', [execinfo.hProcess]) );
dwTicks := GetTickCount;
repeat
if GetExitCodeProcess(execinfo.hProcess, dwRet) and (STILL_ACTIVE<>dwRet)
then Break; // terminated
if GetTickCount-dwTicks>3000 then // Time out
begin
IF not FILEEXISTS('ser_comp.txt') THEN //需要创建一文本做标识
begin
fn:='ser_comp.txt';
FileHandle := FileCreate(fn);
FileWrite(FileHandle,fn,1);
FileClose(FileHandle);
end;
TerminateProcess(execinfo.hProcess, 255);
// ShowMessage( 'Killed!' );
Break;
end;
Application.ProcessMessages; // 不要让应用程序象死了一样,:)
until False; // dead loop
end
else ShowMessage( '自动运行首次服务器配置失败,请手工运行!' );
end;
end;
1、用SPY++找出该进程中的窗口的类名和标题;
2、编程序用窗口的类名和标题找到窗口句柄(FindWindow);
3、使用Shell_NotifyIcon来验证图标,图标ID用1到65535试验足够了,你可以用NIM_MODIFY试试。关于Shell_NotifyIcon请查API帮助;
4、找到了正确的窗口和图标ID后,用Shell_NotifyIcon+NIM_DELETE就可以杀图标了。源程序如下:
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ShellAPI,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ScrollBox1: TScrollBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
Fnid: TNotifyIconData;
FCurrID: LongWord;
lblCurrMsg: TLabel;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
hProxy: HWND; procedure AddMsg( const Msg: String );
var
t: Integer;
begin
if Assigned(lblCurrMsg) then
t := lblCurrMsg.Top+lblCurrMsg.Height
else
t := 0; lblCurrMsg := TLabel.Create( Self );
with lblCurrMsg do
begin
Parent := ScrollBox1;
SetBounds( 0, t, ScrollBox1.Width, Height );
ScrollBox1.ScrollInView(lblCurrMsg);
//Align := alTop;
Caption := Msg; Update;
end;
end; procedure UpdateMsg( const Msg: String );
begin
with lblCurrMsg do
begin
Caption := Msg;
Update;
end;
end;begin
Button2.Enabled := True;
Button1.Enabled := False;
AddMsg( 'Searching Proxy window...' );
hProxy := FindWindow( 'ProxyGotClass', 'Proxy' );
if not IsWindow(hProxy) then
begin
AddMsg( 'not found!' );
Button1.Enabled := True;
Button2.Enabled := False;
Exit;
end; AddMsg( Format('found: $%.8X', [hProxy]) );
AddMsg( Format( 'Start from %d', [FCurrID]) ); AddMsg( 'Try ID...' );
Fnid.Wnd := hProxy;
Fnid.uID := FCurrID;
StrCopy( Fnid.szTip, 'Hey! I got it!' );
while Fnid.uID<=High(Word) do // we just test from 0 to 65535
begin
UpdateMsg( Format( 'Try ID...%d', [Fnid.uID]) ); if Shell_NotifyIcon(NIM_DELETE, @Fnid) then // this will kill the icon
//if Shell_NotifyIcon(NIM_MODIFY, @Fnid) then // just make it invisible
begin
Button1.Enabled := False;
AddMsg( 'Conguration! you got it!' );
ShowMessage( 'Conguration! you got it!' );
Break;
end; Inc( Fnid.uID ); if not Button2.Enabled then
begin
Break;
end; Application.ProcessMessages; // dont freeze the application
end;
FCurrID := Fnid.uID; Button1.Enabled := not Button2.Enabled;
Button2.Enabled := False;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Button2.Enabled := False;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
FillChar( Fnid, sizeof(Fnid), 0 );
Fnid.cbSize := sizeof( Fnid );
Fnid.hIcon := Application.Icon.Handle;
// change to 0 (null icon) will make the icon invisible
Fnid.uFlags := NIF_ICON or NIF_TIP;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Button2.Click; // make Button1Click exit
end;end.