vb script  to start the services is not working

Posted on 2016-10-18
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
strComputer = "VishnuAdithya"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objService In objWMIService.ExecQuery("Select * from Win32_Service Where Name = '"_

Open in new window

Question by:vishnu adithya
  • 2
LVL 17

Expert Comment

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

Expert Comment

ID: 41848035
also check similar case here
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()
End Sub
LVL 35

Accepted Solution

Kimputer earned 500 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.

Author Closing Comment

by:vishnu adithya
ID: 41848928
Kim you are genius! Thanks a lot !!!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

23 Experts available now in Live!

Get 1:1 Help Now