I was writing some unit test using CppUnit for some methods. I needed to test some methods which was written in windows to manipulate windows services.
Below is basically a rough idea on how to do this:
One such example is a method which tests the windows service state. Let us call this method
TestServiceState():
The best way to test such a method would be to take a windows service present in all XP computers. I took a method called MSISErver. This basically is called a windows installer service.
Now you can make use of MSDN libraries to open a service manager.
Handle schSCManager;
schSCManager = OpenSCManager(
NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
now with the help of this handle you can open a service, but not start a service with the keyword
SERVICE_ALL_ACCESS and open service method.
Next you can query the service: with QueryServiceStatusEX and then find out the status of your service. You can incorporate this into your Unit tests with the idea above.
Leave a Reply