KB-81331: Stopping/Starting Windows services via Elipse E3 scripts.

Question:

Can Windows services be stopped/started via Elipse E3 scripts?

Solution:

Yes, they can. To do so, insert the script bellow into the Click event of a button interacting with the SQL Server database:

set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name = 'MSSQL$SQLEXPRESS'")
for each objService in colServiceList
if objService.state = "Running" then
objService.StopService() 'stop service
else
objService.StartService() 'start service
end if
next

This script uses (Windows Management Instrumentation) objects. For further information about these objects, check this article.

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *