Vbs Script to stop a process, the start and stop a service

Posted on 2009-07-13
Last Modified: 2012-06-27
i need avbs script to stop     thisprocess.exe, the stop a service  "updates" and then start the updates service
Question by:underground712
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 67

Accepted Solution

sirbounty earned 125 total points
ID: 24842123
Modified from
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strProcess = "'thisprocess.exe'" 
strService = "'updates'"
intSleep = 10000 '10 second delay
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcess )
For Each objProcess in colProcess
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name = " & strService )
For Each objService in colListOfServices
  WSCript.Sleep intSleep

Open in new window


Expert Comment

ID: 24842154
Here's how to stop and start a service:

Note* You will need WSH to make this work. Download here:

Option Explicit
Dim objWService, objItem, objService
Dim colList, strService, intSleep, strComp
'Leave as is for local machine.
strComp = "."
'Time to wait until restart
intSleep = 15000
WScript.Echo " Click OK, then wait " & intSleep & " milliseconds"
strService = " 'updates' "
Set objWService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComp & "\root\cimv2")
Set colList = objWService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " ")
For Each objService in colList
    WSCript.Sleep intSleep
WScript.Echo "Your "& strService & " service has Started"

Open in new window


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question