 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The VBScript Network and Systems Administrator&#039;s Cafe &#187; kill process</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/kill-process/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Using WMI&#8217;s WIN32_Process class to remotely kill a process</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-wmis-win32_process-classes-to-remotely-kill-a-process/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-wmis-win32_process-classes-to-remotely-kill-a-process/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 21:22:13 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[kill]]></category>
		<category><![CDATA[kill process]]></category>
		<category><![CDATA[Kill processes]]></category>
		<category><![CDATA[pkill]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[win32_process]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-wmis-win32_process-classes-to-remotely-kill-a-process/</guid>
		<description><![CDATA[Recently I had a situation where I had to kill a number of processes on a number of servers in a short period of time so we could update the executable file quickly so the processes could be safely respawned. This presented a challenge because it needed to be done quickly both before users respawned [...]]]></description>
				<content:encoded><![CDATA[<p>Recently I had a situation where I had to kill a number of processes on a number of servers in a short period of time so we could update the executable file quickly so the processes could be safely respawned. This presented a challenge because it needed to be done quickly both before users respawned the process multiple times on each server and because the number of servers involved did not lend itself to simply logging onto the server and killing the processes one server at a time.</p>
<p>So I pulled out the scripting hat and went to work making use of the WMI Win32_Process class to create the following function that gets passed the process name you want to kill and the remote server name where you want to kill the processes.   Worked like a champ! One hitch was that there were users still on the server, but that was solved by simply running the script multiple times while we copied the new files to the servers.</p>
<p>So, here is the function I spoke about&#8230; hopefully you can add it to your list of script tools in your scripting tool belt!<br />
<span style="color: #0000ff">Function RemoteKill( StrComputer1, ProcessName)</span></p>
<p><span style="color: #0000ff">    Dim objWMIService, colItems, objItem</span></p>
<p><span style="color: #0000ff">    On Error Resume Next<br />
    &#8216; error control block<br />
    Set objWMIService = GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}//&#8221; &amp;  strComputer1 &amp; &#8220;\root\cimv2&#8243;)<br />
    Set colItems = objWMIService.ExecQuery (&#8220;Select * from Win32_Process Where Name = &#8216;&#8221; &amp; ProcessName &amp; &#8220;&#8216;&#8221;)<br />
    For Each objItem in colItems<br />
        RemoteKill = RemoteKill &amp; VbCrLf &amp; strComputer1 &amp; &#8220;: &#8221;<br />
        RemoteKill = RemoteKill &amp; objItem.name &amp; &#8220;(PID: &#8221; &amp; objItem.processid &amp; &#8220;) Terminated.&#8221;<br />
        ObjItem.terminate<br />
    Next<br />
    On Error GoTo 0<br />
End Function</span></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-wmis-win32_process-classes-to-remotely-kill-a-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
