怎么样用TerminateProcess结束一个进程??谢谢(100分)

  • 主题发起人 主题发起人 felong11
  • 开始时间 开始时间
F

felong11

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么样用TerminateProcess结束一个进程?<br>请大虾讲一下。<br>特别好就是有例程。<br>谢谢
 
BOOL TerminateProcess(<br><br>&nbsp; &nbsp; HANDLE hProcess, // handle to the process <br>&nbsp; &nbsp; UINT uExitCode // exit code for the process &nbsp;<br>&nbsp; &nbsp;);<br>delphi帮助上有的。<br>另外我编的程序(用了该函数)在win2000下就没法生效了,倒是也没有报错。<br>那位大虾顺便给分析分析:)
 
我就是在win2k下做,请大家指教。!!!!!<br>我怎么也做不起来。请大虾帮帮我把。<br>它怎么也不肯关闭!!!!<br>
 
HANDLE hProcess<br>Windows NT/2000: The handle must have PROCESS_TERMINATE access. <br>For more information, see Process Security and Access Rights. <br><br>所以要先使用 <br>DWORD SetSecurityInfo(<br>&nbsp; HANDLE handle, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // handle to object<br>&nbsp; SE_OBJECT_TYPE ObjectType, &nbsp; &nbsp; &nbsp; &nbsp; // object type<br>&nbsp; SECURITY_INFORMATION SecurityInfo, // buffer<br>&nbsp; PSID psidOwner, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// new owner SID<br>&nbsp; PSID psidGroup, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// new primary group SID<br>&nbsp; PACL pDacl, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// new DACL<br>&nbsp; PACL pSacl &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // new SACL<br>);<br>
 
如果使用delphi的tthread类呢?
 
tthread 有 Handle 属性。
 
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; StartInfo &nbsp;: TStartupInfo;<br>&nbsp; ProcInfo &nbsp; : TProcessInformation;<br>&nbsp; CreateOK &nbsp; : Boolean;<br>&nbsp; ProgramName: String;<br>begin<br>&nbsp; ProgramName := 'calc.exe';<br>&nbsp; FillChar(StartInfo,SizeOf(TStartupInfo),#0);<br>&nbsp; FillChar(ProcInfo,SizeOf(TProcessInformation),#0);<br>&nbsp; StartInfo.cb := SizeOf(TStartupInfo);<br>&nbsp; CreateOK := CreateProcess(nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PChar(ProgramName), nil, nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; False,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREATE_NEW_PROCESS_GROUP +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil, nil, StartInfo, ProcInfo);<br>&nbsp; Sleep(1000);<br>&nbsp; if CreateOK then<br>&nbsp; TerminateProcess(ProcInfo.hProcess, 0);<br>end;
 
:mikedeakins<br>我在编写一些比如win2k的关机的事情是不是也要加这样语句呢???<br><br>谢谢
 
你是要编写程序关闭 Windows 2000 吗?2000 的关机例程好像是先发消息,不响应的<br>就强行关闭。我不明白你问的是什么样的程序。
 
这是我的部分代码(我自己做的小程序中的,肯定可以,98下和2000下都通过了)<br>var<br>&nbsp; dwProc:THandle;<br>&nbsp; mypro:string;<br>&nbsp; processid:cardinal;<br>&nbsp; id1:variant;<br>begin<br>&nbsp;....<br>//取得当前要关闭的程序的句柄,processid是一个进程的ID<br>&nbsp; dwProc:=OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE,FALSE,dword(ProcessID));<br>&nbsp; terminateprocess(dwProc,0)<br>就这么简单:)<br>
 
关闭 Windows 2000 看看我的回答吧
 
怎样不用<br>dwProc:=OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE,FALSE,dword(ProcessID));<br>&nbsp; terminateprocess(dwProc,0)<br>获取句柄??<br>我要结束任意一个进程。<br>在结束一个DCOM的进程的时候怎么不让它弹出确认的对话框??<br>
 
多人接受答案了。
 
请问楼上的各位老兄,请问用<br><br>&nbsp; dwProc:=OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE,FALSE,dword(ProcessID));<br>得到的dwProc,我将dwProc传给另外的进程。<br>在另外的进程用<br>&nbsp; terminateprocess(dwProc,0)<br>却不能将进程删了。<br>请问我如何做。谢谢。<br><br>
 
后退
顶部