473,394 Members | 1,951 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.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. ' ------ SCRIPT CONFIGURATION ------
  4. Dim strComputer : strComputer = "."
  5. Dim strSvcName : strSvcName = "Alerter"
  6. ' ------ END CONFIGURATION ---------
  7.  
  8. Dim objWMI : set objWMI = GetObject("winmgmts:\\" & strComputer & _
  9. "\root\cimv2")
  10. Dim objService: set objService = objWMI.Get("Win32_Service.Name='" & _
  11. strSvcName & "'")
  12.  
  13. WScript.Echo "Restarting " & objService.Name & "..."
  14. RecursiveServiceStop objService
  15. RecursiveServiceStart objService
  16. WScript.Echo "Successfully restarted service"
  17.  
  18. Function RecursiveServiceStop ( objSvc ) 
  19.  
  20. Dim colServices : set colServices = objWMI.ExecQuery("Associators of " _
  21. & "{Win32_Service.Name='" & objSvc.Name & "'} Where " _
  22. & "AssocClass=Win32_DependentService Role=Antecedent" )
  23.  
  24. Dim objS
  25. for each objS in colServices
  26. RecursiveServiceStop objS
  27. next
  28.  
  29. Dim intRC : intRC = objSvc.StopService
  30. if intRC > 0 then
  31. WScript.Echo " Error stopping service: " & objSvc.Name
  32. WScript.Quit
  33. else
  34. WScript.Echo " Successfully stopped service: " & objSvc.Name
  35. end if
  36. End Function
  37.  
  38. Function RecursiveServiceStart ( objSvc )
  39.  
  40. Dim intRC : intRC = objSvc.StartService
  41. if intRC > 0 then
  42. WScript.Echo " Error starting service: " & objSvc.Name
  43. WScript.Quit
  44. else
  45. WScript.Echo " Successfully started service: " & objSvc.Name
  46. end if
  47.  
  48. Dim colServices : set colServices = objWMI.ExecQuery("Associators of " _
  49. & "{Win32_Service.Name='" & objSvc.Name & "'} Where " _
  50. & "AssocClass=Win32_DependentService Role=Antecedent" )
  51.  
  52. Dim objS
  53. for each objS in colServices
  54. RecursiveServiceStart objS
  55. next
  56.  
  57. End Function
Nov 18 '06 #1
0 1059

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...
3
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: s.kapitza | last post by:
Hi, try M$S servicebug 3 regards s.kapitza alghaden@alumni.fdu.edu (Ahmad) wrote in message news:<4a75f4b7.0308080649.49105373@posting.google.com>...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.