I am totally new to scripting. I've researched how to write a Windows Management Instrumentation(WMI) moniker to check which services on my local machine (that have been set to Automatic) are stopped:
' Listing 9. Code Using an ExecQuery Statement to List Nonrunning Automatic Services
strWMIMoniker = "winmgmts:!//VICKY09"
strQuery = "select * from Win32_Service where State+'Stopped' and StartMode='Auto'"
Set wmiWin32Services = GetObject(strWMIMoniker).ExecQuery(strQuery)
If wmiWin32Services.Count = 0 Then
WScript.Echo "There were no services that matched your query."
Else
For Each wmiWin32Service in wmiWin32Services
WScript.Echo wmiWin32Service.Description
Next
End If
My question is how can I direct the wmiWine32Service.Description to a .txt file? I remember back in the batch file days, I could use the > sign to redirect to a file, but when I tried that in this script I got an error.
I want to be able to capture any services that have been stopped so I can e-mail myself as an alert.
Any help would be greatly appreciated.
' Listing 9. Code Using an ExecQuery Statement to List Nonrunning Automatic Services
strWMIMoniker = "winmgmts:!//VICKY09"
strQuery = "select * from Win32_Service where State+'Stopped' and StartMode='Auto'"
Set wmiWin32Services = GetObject(strWMIMoniker).ExecQuery(strQuery)
If wmiWin32Services.Count = 0 Then
WScript.Echo "There were no services that matched your query."
Else
For Each wmiWin32Service in wmiWin32Services
WScript.Echo wmiWin32Service.Description
Next
End If
My question is how can I direct the wmiWine32Service.Description to a .txt file? I remember back in the batch file days, I could use the > sign to redirect to a file, but when I tried that in this script I got an error.
I want to be able to capture any services that have been stopped so I can e-mail myself as an alert.
Any help would be greatly appreciated.