Scripting Win32 Provider Methods
Scripting Win32 Provider Methods
This topic provides scripts that demonstrate using the Win32_Service class to start and stop Speech Engine Services (SES) and Telephony Application Services (TAS).
For more information, see the topic on the Win32_Service class.
Starting TAS
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name='TAS'") For Each objService in colServiceList errReturn = objService.StartService() Next WScript.Sleep 20000 Set colServiceList = objWMIService.ExecQuery("Associators of " _ & "{Win32_Service.Name='TAS'} Where " _ & "AssocClass=Win32_DependentService " & "Role=Dependent" ) For Each objService in colServiceList objService.StartService() Next
Stopping TAS
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery("Associators of " _ & "{Win32_Service.Name='TAS'} Where " _ & "AssocClass=Win32_DependentService " & "Role=Antecedent" ) For Each objService in colServiceList objService.StopService() Next WScript.Sleep 20000 Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name='TAS'") For Each objService in colServiceList errReturn = objService.StopService() Next
Starting SES
Starting SES requires starting dependent services, and so the script differs slightly from the TAS examples.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name='SES'") For Each objService in colServiceList errReturn = objService.StartService() Next WScript.Sleep 20000
Stopping SES
This script stops SES and dependent services.
strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery("Associators of " & "{Win32_Service.Name='SES'} Where " & "AssocClass=Win32_DependentService " & "Role=Antecedent" ) For Each objService in colServiceList objService.StopService() Next WScript.Sleep 20000 Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='SES'") For Each objService in colServiceList errReturn = objService.StopService() Next
See Also
Administering Microsoft Speech Server with WMI | Invoking Methods of Windows Management Instrumentation Objects