Solved

vb script  to start the services is not working

Posted on 2016-10-18
4
24 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:vishnu adithya
  • 2
4 Comments
 
LVL 17

Expert Comment

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

Expert Comment

by:xtermie
Comment Utility
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 35

Accepted Solution

by:
Kimputer earned 500 total points
Comment Utility
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:vishnu adithya
Comment Utility
Kim you are genius! Thanks a lot !!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now