472,784 Members | 1,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

starting disabled service VBS/WMI

Hi, I need some help, i don't know much about programming other than executing them get getting them from scripting sites. My program is it won't start a service if the startup type is Disabled. it will try and stop a service that is disabled and will display msg "Error stopping service." if i run script on a service that is already running, it stop then start the service and restarts it again. Thanks whoever has the time to help me.

Option Explicit

' ------ SCRIPT CONFIGURATION ------
Dim strComputer : strComputer = "."
Dim strSvcName : strSvcName = "Alerter"
' ------ END CONFIGURATION ---------

Dim objWMI : set objWMI = GetObject("winmgmts:\\" & strComputer & _
"\root\cimv2")
Dim objService: set objService = objWMI.Get("Win32_Service.Name='" & _
strSvcName & "'")

WScript.Echo "Restarting " & objService.Name & "..."
RecursiveServiceStop objService
RecursiveServiceStart objService
WScript.Echo "Successfully restarted service"

Function RecursiveServiceStop ( objSvc )

Dim colServices : set colServices = objWMI.ExecQuery("Associators of " _
& "{Win32_Service.Name='" & objSvc.Name & "'} Where " _
& "AssocClass=Win32_DependentService Role=Antecedent" )

Dim objS
for each objS in colServices
RecursiveServiceStop objS
next

Dim intRC : intRC = objSvc.StopService
if intRC > 0 then
WScript.Echo " Error stopping service: " & objSvc.Name
WScript.Quit
else
WScript.Echo " Successfully stopped service: " & objSvc.Name
end if
End Function

Function RecursiveServiceStart ( objSvc )

Dim intRC : intRC = objSvc.StartService
if intRC > 0 then
WScript.Echo " Error starting service: " & objSvc.Name
WScript.Quit
else
WScript.Echo " Successfully started service: " & objSvc.Name
end if

Dim colServices : set colServices = objWMI.ExecQuery("Associators of " _
& "{Win32_Service.Name='" & objSvc.Name & "'} Where " _
& "AssocClass=Win32_DependentService Role=Antecedent" )

Dim objS
for each objS in colServices
RecursiveServiceStart objS
next

End Function
Nov 18 '06 #1
3 4066
bartonc
6,596 Expert 4TB
Hello, and welcome.

Two thinks will help you a lot:
1) Use code tags in your post.
2) Post your question in the VB forum at http://www.thescripts.com/forum/forum132.html

Thanks for posting - keep it up!
Nov 18 '06 #2
Sorry, i just joined and i figured the script is also for administration. thanks
Nov 18 '06 #3
bartonc
6,596 Expert 4TB
Sorry, i just joined and i figured the script is also for administration. thanks
Thanks for keeping this thread up-to-date. I hope the VB people can help you.
Nov 18 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt Rapoport | last post by:
I'd like to programmatically remove a service or change its startup type to disabled. I know how to remove it from the command line but is there another way using the win32 extensions? I've...
2
by: ceadtinneh | last post by:
Folks, We're implementing a software based mirroring solution. This solution requires that the SQL Server service on the target server be stopped while data is being replicated from the source...
0
by: tshad | last post by:
I have a Windows Service I created that just sets a timer and writes to EventLog every 10 seconds. It installed fine and it actually starts. But it says it doesn't. The progress bar shows the...
3
by: yxq | last post by:
Hello I want to start a disabled service using VB.Net, i use the start propetry in ServiceController class, but it can not start a disabled service, how to do? Many thanks
6
by: Arnie | last post by:
We're using the ServiceController class provided by the .NET Framework, programming in C#. We are using the Start() method to start a service from another service. This works fine most of the...
2
by: ssg31415926 | last post by:
I'm trying to debug a new web application and I get: "Unable to start debugging on the web server. The Visual Studio 2005 Remote Debugger service is unable to connect to this computer. Please see...
0
by: Cenarius | last post by:
Hi, I need some help, i don't know much about programming other than executing them get getting them from scripting sites. My program is it won't start a service if the startup type is Disabled. it...
5
by: eliasen | last post by:
Hi I have created a Windows Service using C# and .NET2.0. The service is quite simple - right now it doesn't do anything except throwing an exception in the OnStart method. It used to something...
1
by: ropo | last post by:
I have a .NET 2.0 app that at one point starts an old MFC App through System.Diagnostics.Process.Start from a model form/ I then wait for it to finish by calling StartedProcess.WaitForExit(); ...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.