'==========================================================================
'
'
' NAME: <ServiceAccount.vbs>Logged
'
' AUTHOR: Ed Wilson , MS
' DATE  : 5/3/2006
'
' COMMENT: <Uses the startName property from win32_service>
'1. filter out services using localSystem account.
'==========================================================================

Option Explicit 
'On Error Resume Next
dim strComputer			'target computer
dim wmiNS						'target wmi name space
dim wmiQuery				'the WMI query
dim objWMIService		'sWbemservices object
dim colItems				'sWbemObjectSet object
dim objItem					'sWbemObject
Dim strProperties		'properties to Select
Dim strValues				'string of wmi values

strComputer = "."
wmiNS = "\root\cimv2"
strProperties = "name,StartName,started"
wmiQuery = "Select " & strProperties & " from win32_service" &_
	" where startName <> 'localSystem'"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)
subText(strProperties)
For Each objItem In colItems
strValues = objItem.name & "," & objItem.StartName & _
	"," & objItem.started

subText(strValues)
Next

'*** Subs and functions below ***

Sub subText(strIN)
Dim objfso		'the filesystemobject
Dim objfile		'file object
Dim objshell	'wshshell object
Dim strPath		'path to desktop
Dim strFile		'log file name

Const ForAppending = 8
Const createFile = True
strFile = funfix("logService.csv") 'adds \ to file name

Set objshell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = objshell.SpecialFolders("desktop")
strFile = strPath & strFile
Set objfile = objfso.OpenTextFile(strFile,ForAppending,createFile)
objfile.WriteLine (strIN)
End Sub

Function funfix (strIN)
funfix = "\" & strin
End Function