关于系统进程的问题(90分)

  • 主题发起人 主题发起人 kim_fu
  • 开始时间 开始时间
K

kim_fu

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,<br>&nbsp; ExtCtrls,TLHelp32;<br><br>type<br>&nbsp; TRunMyApp = class(TService)<br>&nbsp; &nbsp; procedure ServiceExecute(Sender: TService);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; function GetServiceController: TServiceController; override;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; RunMyApp: TRunMyApp;<br>implementation<br><br>{$R *.DFM}<br><br>procedure ServiceController(CtrlCode: DWord); stdcall;<br>begin<br>&nbsp; RunMyApp.Controller(CtrlCode);<br>end;<br><br>function TRunMyApp.GetServiceController: TServiceController;<br>begin<br>&nbsp; Result := ServiceController;<br>end;<br><br>procedure TRunMyApp.ServiceExecute(Sender: TService);<br>var Timer,i:Integer;<br>// &nbsp; &nbsp;lpStartupInfo: TStartupInfo;<br>// &nbsp; &nbsp;lpProcessInformation: TProcessInformation;<br>&nbsp; &nbsp; lppe: TProcessEntry32;<br>&nbsp; &nbsp; found,runing : boolean;<br>&nbsp; &nbsp; Hand : THandle;<br>&nbsp; &nbsp; aList:TStringList;<br>&nbsp; &nbsp; execnames:String;<br>begin<br>&nbsp; &nbsp; Timer:=3000;<br>&nbsp; &nbsp; execnames:='NOTEPAD.EXE';<br>&nbsp; &nbsp; while true do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; aList:=TStringList.Create;<br>&nbsp; &nbsp; &nbsp; &nbsp; aList.Clear;<br>&nbsp; &nbsp; &nbsp; &nbsp; Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; found := Process32First(Hand,lppe);<br>&nbsp; &nbsp; &nbsp; &nbsp; while found do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aList.Add(StrPas(lppe.szExeFile));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; found := Process32Next(Hand,lppe);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; runing:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; for i:=0 to aList.Count-1 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if UpperCase(aList.Strings)=execnames then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; runing:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; //CreateProcess('','NOTEPAD.EXE',nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,lpStartupInfo,lpProcessInformation);<br>&nbsp; &nbsp; &nbsp; &nbsp; if not runing then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; winexec('c:/WINNT/NOTEPAD.exe',SW_SHOW);<br>&nbsp; &nbsp; &nbsp; &nbsp; sleep(Timer);<br>&nbsp; &nbsp; end;<br>end;<br><br><br>end.<br><br>服务能正常启动,但是有时系统进程的列表不好使found返回false<br>一个劲的运行notepad.exe<br>而且notepad.exe总是在后台进行,只能在进程列表里看到,而看不到窗口,为什么<br>你的帮助对我一生很重要。wait........
 
服务程序不处理窗口消息,所以不能有界面<br><br>-----<br>http://www.8421.org
 
我也试了,写成一个在工具栏驻留的程序<br>可是写成那样之后<br>&nbsp; &nbsp; &nbsp; Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; found := Process32First(Hand,lppe);<br>hand返回正常,found总是false,根本读不出进程列表
 
这样的问题我遇到过,不过我将程序的名称改过之后就没有问题了:)<br>可能是应用程序没有完全释放吧,或者重新启动以下系统,<br>如果有好的解决办法请通知在下!!<br>先谢谢了!!<br>
 
我也没读出进程为什么??
 
奇怪。。。
 
后退
顶部