473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 4103
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.