{"id":686,"date":"2009-10-21T13:33:00","date_gmt":"2009-10-21T05:33:00","guid":{"rendered":""},"modified":"2013-11-17T16:59:45","modified_gmt":"2013-11-17T08:59:45","slug":"delphi%e7%bb%93%e6%9d%9f%e8%bf%9b%e7%a8%8b%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/686.html","title":{"rendered":"Delphi\u7ed3\u675f\u8fdb\u7a0b\u6a21\u5757"},"content":{"rendered":"<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nuses Tlhelp32;\r\n\r\nfunction KillTask(ExeFileName: string): integer;\r\nconst\r\n  PROCESS_TERMINATE = $0001;\r\nvar\r\n  ContinueLoop: BOOLean;\r\n  FSnapshotHandle: THandle;\r\n  FProcessEntry32: TProcessEntry32;\r\nbegin\r\n  Result := 0;\r\n  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\r\n  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);\r\n  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);\r\n  while integer(ContinueLoop) &lt;&gt; 0 do\r\n  begin\r\n    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase\r\n          (ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase\r\n          (ExeFileName))) then\r\n      Result := integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0)\r\n              , FProcessEntry32.th32ProcessID), 0));\r\n    ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);\r\n  end;\r\n  CloseHandle(FSnapshotHandle);\r\nend;\r\n<\/pre>\n<p>\u8c03\u7528\u7684\u65f6\u5019\u53ea\u9700\u8981<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nif KillTask('qq.exe') &lt;&gt; 0 then\r\n    showmessage('\u7ed3\u675fQQ\u6210\u529f')\r\nelse\r\n    showmessage('\u65e0\u6cd5\u7ed3\u675fQQ');\r\n<\/pre>\n<p>\u4f60\u5728\u7a0b\u5e8f\u91cc\u9762\u7528\u4e00\u4e2a\u8ba1\u65f6\u5668\uff0c\u6bcf\u9694\u4e00\u79d2\u949f\u68c0\u67e5\u4e00\u4e0b\uff0c\u5982\u679c\u6709\u5c31\u7ed3\u675f\uff0c\u4e5f\u5c31\u5b9e\u73b0\u4e86\u7981\u6b62\u8fd0\u884c\u7684\u76ee\u7684\u3002<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nprocedure TForm1.Timer1Timer(Sender: TObject);\r\nbegin\r\n    KillTask('qq.exe');\r\nend;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>uses Tlhelp32; function KillTask(ExeFileName: string):  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-686","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=686"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/686\/revisions"}],"predecessor-version":[{"id":4715,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/686\/revisions\/4715"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}