Start and Stop Windows Services

Today we will be dealing with something not a QTP specific feature but its more to do with VB script. Lets say we need to start or stop a windows service like DHCP Client, Netlogon etc. This can be automated using VB script and in QTP without the need to open the Services window. Lets see how to do this.
Certain tests might need to be developed by starting or stopping certain services and then validate certain conditions. So this should be very helpful while developing certain tests. The basic code has been taken from MSDN where a very good example has been given.
There are a few things that we would be doing here
Get the WMI (Windows Management Instrumentation or Windows Management Interface) object
Execute a query to get the list of services
Start/Stop the service
Below you can see how we can get the list of all services. Click on the image to see the code.



To start or stop a service all that we need to do is to use the StartService() or StopService() method.  However, for that we would need to modify our query slightly. This is what we would need to do.Click on the image to see the code.





Notice the extra "quotes" used for the service name and that is because in the query we would need to have the filter in quotes.
Hope this helped.

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (0)

0 Response to "Start and Stop Windows Services"

Post a Comment

Visitors

Website Counter