﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-Carl's Blog-最新评论</title><link>http://www.cnitblog.com/Carl/CommentsRSS.aspx</link><description /><language>zh-cn</language><pubDate>Sun, 06 Apr 2008 16:10:01 GMT</pubDate><lastBuildDate>Sun, 06 Apr 2008 16:10:01 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: 结束系统进程的一些指令</title><link>http://www.cnitblog.com/Carl/archive/2007/05/25/27574.html#27575</link><dc:creator>Carl li</dc:creator><author>Carl li</author><pubDate>Thu, 24 May 2007 17:29:00 GMT</pubDate><guid>http://www.cnitblog.com/Carl/archive/2007/05/25/27574.html#27575</guid><description><![CDATA[CMD中可执行的结束进程命令<br>[ 2006-9-15 23:47:00 | By: hkzj ]<br>一、CMD中可执行的结束进程命令（其实是一个远程关机工具） <br>ntsd -c q -p pid  (pid 为进程标识符，在任务管理器中可以调出这一属性列)<br>例:<br>如explorer.exe的pid为1332,则<br>运行:<br>ntsd -c q -p 1332就能结束explorer.exe进程<br><br>ntsd -c q -pn ***.exe (***.exe 为进程名,exe不能省)<br>例:<br>运行:ntsd -c q -pn explorer.exe就结束explorer.exe进程<br><br>二、应用<br><br>因为这个命令要比任务管理器中的结束进程功能强，所以我另外做了一个进程结束器，以VB为环境，利用ntsd命令和shell函数就能搞出来了。<br>思路:<br>先创建一个批处理文件(直接让CMD接受命令变量感觉不行,而这个文件可以直接在CMD中执行),，预先写入ntsd -c q -p ，然后接受输入的pid，传送PID到BAT文件，点击按钮执行BAT文件。<br>因为涉及文件操作,所以要在工程中引用microsoft scripting runtime<br>下面是代码:<br><br>Dim ts As New FileSystemObject<br>Dim tf As TextStream<br><br>Private Sub Command1_Click()<br><br>Set ts = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br><br>Set tf = ts.CreateTextFile(&quot;d:\1.bat&quot;)<br><br>tf.Write (&quot;ntsd -c q -p &quot;)  '预先写好前段命令<br>tf.Write (Text1.Text)     '等待写入进程PID<br>tf.Close<br><br>Shell &quot;D:\1.bat&quot;, vbMinimizedFocus '最小化执行结束进程命令<br>Text1.Text = &quot;&quot;<br>End Sub<br><br>Private Sub Form_Unload(Cancel As Integer)<br>Shell &quot;cmd /c del d:\1.bat&quot;, vbMinimizedFocus '关闭时删除临时文件<br>End Sub<br><br><br>另外一个程序，这个是用输‘进程名’并用‘winexec’来结束进程的代码:<br><br>Dim ts As New FileSystemObject<br>Dim tf As TextStream<br>Dim df As File<br><br>Private Declare Function WinExec Lib &quot;kernel32&quot; (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long<br><br><br>Private Sub Command1_Click()<br>Set ts = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br><br>Set tf = ts.CreateTextFile(&quot;d:\1.bat&quot;)<br><br>tf.Write (&quot;ntsd -c q -pn &quot;)  '预先写好前段命令<br>tf.Write (Text1.Text)     '等待写入进程PID<br>tf.Close<br><br>WinExec &quot;D:\1.bat&quot;, 3 '执行命令<br><br>Text1.Text = &quot;&quot;<br>End Sub<br><br>Private Sub Form_Unload(Cancel As Integer)<br>Set df = ts.GetFile(&quot;d:\1.bat&quot;)<br>ts.DeleteFile (df) '关闭时删除临时文件,跟上面方法不一样<br>End Sub<br><br>其实taskkill的进程控制功能更强，不过只有WINXP以上才有。<br><br><img src ="http://www.cnitblog.com/Carl/aggbug/27575.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Carl/" target="_blank">Carl li</a> 2007-05-25 01:29 <a href="http://www.cnitblog.com/Carl/archive/2007/05/25/27574.html#27575#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>