• Home
  • Billiards
  • Classic ASP
  • Browse Blog
    • Halifax
    • Internet
    • Internet Marketing
    • Programming
    • SEO
    • sitemap
    • Skateboarding
    • technology
      • Automation
    • travel
    • Web Development
    • Web Hosting
    • Website Management
    • wedding
  • Subscribe via RSS

VBScript to Terminate a Windows Process

April 10th, 2009  |  Published in Programming, technology, Web Development




I needed a quick vbscript to terminate a specific windows process that seemed to hang. This is the script that will do it. It uses SQL to lookup the process name from the win32_process list, then uses the terminate function to close it.

NOTE: this vbs to terminate a windows process was only tested on Windows XP professional edition.

Just leave strComputer variable as-is if you are using it on the same machine as the process you want terminated. Replace the ENTER_PROCESS_NAME_HERE portion of the code with your process name. (to find a windows process name, just go to the windows task manager, click “processes” and the name that appears in the “process name” column is the string you should enter.)

1
2
3
4
5
6
7
8
9
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Process WHERE Name = 'ENTER_PROCESS_NAME_HERE'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcessList = objWMIService.ExecQuery _ ("SELECT * FROM Win32_Process WHERE Name = 'ENTER_PROCESS_NAME_HERE'") For Each objProcess in colProcessList objProcess.Terminate() Next

The for loop ensures that if there are multiple processes open that match your query, all of them get terminated. If you are looking to terminate a specific process, make sure you enter it’s full name, and make sure you research other processes so that you don’t terminate other processes that you didn’t intend to.

If you want to terminate multiple, but similar processes, you can use wildcard, just like in any sql statement.

1
SELECT * FROM Win32_Process WHERE Name LIKE 'm%'

SELECT * FROM Win32_Process WHERE Name LIKE 'm%'

This code will select all processes beginning with the letter M, for example.

Hope this helps. Comments welcome.

Leave a Response

Tags

1and1 adsense asp caribbean classic asp crowdsourcing CTR cuba Cueva de Pirata customer service database dominican republic forum management godaddy google Halifax hosting hotel ideagora Internet Linux MySQL objWmiService outsourcing php Pirates Cave plugin scripting scripts SEO Skateboarding sql travel Varadero vbs vbscript web browser web development wedding What is Crowdsourcing? wikipedia windows windows scripting winmgmts xp

Pages

  • About Robar’s Pages
    • Privacy Policy for robarspages.ca
  • Classic ASP Programming and Development
  • Gran Bahia Principe Wedding
  • YouTube Extension Plugins for WordPress

Categories

  • Automation
  • Halifax
  • Internet
  • Internet Marketing
  • Programming
  • SEO
  • sitemap
  • Skateboarding
  • technology
  • travel
  • Web Development
  • Web Hosting
  • Website Management
  • wedding

Recent Posts

  • HTTP_X_EAC_REQUEST
  • eZooms Bot User Agent
  • SQL Full Outer Join Three Tables
  • Classic ASP Data Caching for Performance
  • Comparing OLE DB and ODBC Connections

Recent Comments

  • AP on 1and1 Corporate Headquarters Phone Number
  • AJ on 1and1 Corporate Headquarters Phone Number
  • cordova on 1and1 Corporate Headquarters Phone Number
  • mike on 1and1 Corporate Headquarters Phone Number
  • David on Regex MM/YYYY Regular Expression for Credit Card Expiration Date
©2023 Robar's Pages
Sitemap and Table Of Contents