[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

vb script  to start the services is not working

Posted on 2016-10-18
4
Medium Priority
?
99 Views
Last Modified: 2016-10-18
trying to start the vb script but unfortunately its not working, need your help pls
Option Explicit
Dim objWMIService, objService
Dim strService,strComputer,waitTime
strService="Audiosrv"
strComputer = "VishnuAdithya"
waitTime=10000
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objService In objWMIService.ExecQuery("Select * from Win32_Service Where Name = '"_
&strService&"'")
objService.StartService() 
 
Next
 
WScript.Quit

Open in new window

0
Comment
Question by:V Thrusher
[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
4 Comments
 
LVL 18

Expert Comment

by:xtermie
ID: 41848031
try
Set colRunningServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name = '"& strService & "'")
    For Each objService in colRunningServices
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41848035
also check similar case here
https://blogs.technet.microsoft.com/kevinholman/2016/01/24/writing-a-service-recovery-script-cluster-service-example/
like:
Sub ServiceStart(strService)
    Dim objWMIService, colRunningServices, objService, colServiceList
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='"& strService & "'")
    For Each objService in colServiceList
        errReturn = objService.StartService()
    Next
End Sub
0
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 41848329
The script works. You probably forgot the run it through administrator rights. If you log in as administrator (or someone with admin rights), double clicking on the VBS still doesn't work. You need to start an admin cmd box, then start the VBS.
It's either that, or use scheduled tasks to get it to work.
1
 

Author Closing Comment

by:V Thrusher
ID: 41848928
Kim you are genius! Thanks a lot !!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 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