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.