Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-13
2
Medium Priority
?
759 Views
Last Modified: 2012-06-27
i need avbs script to stop     thisprocess.exe, the stop a service  "updates" and then start the updates service
0
Comment
Question by:underground712
[X]
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
2 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 24842123
Modified from http://www.computerperformance.co.uk/vbscript/wmi_services.htm
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
  objProcess.Terminate()
Next 
 
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name = " & strService )
 
For Each objService in colListOfServices
  objService.StopService()
  WSCript.Sleep intSleep
  objService.StartService()
Next

Open in new window

0
 
LVL 3

Expert Comment

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

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

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=47809025-d896-482e-a0d6-524e7e844d81

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
    objService.StopService()
    WSCript.Sleep intSleep
    objService.StartService()
Next
 
WScript.Echo "Your "& strService & " service has Started"
WScript.Quit

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

670 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