'Author      : Ramesh Srinivasan
'Homepage    : http://windowsxp.mvps.org
'Dated       : February 09, 2005
'Description : 'This script detects all orphaned services which cause.....
'....the following error while viewing running services via Help and Support
'--------------------------------------------------
' Error "'inst.PathName' is null or not an object"
'--------------------------------------------------

Dim dirtyflags
Set wshshell = CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
set b = fso.CreateTextFile("C:\OrphServices.txt",true)
b.writeline "Services with missing ImagePath value"
b.writeline string(38,"-")
b.writeblanklines 1

dirtyflags = "No"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service")

For Each objService in colServiceList
On Error Resume Next
	if not objservice.PathName = "" then
		
	else
		b.writeline "Service      : " & objservice.Name	
		b.writeline "Display      : " & objservice.DisplayName
		b.writeline "Image Path   : " & objservice.PathName
		b.writeblanklines 1
		dirtyflags = "Yes"
	end if
Next

if dirtyflags = "No" then
	b.writeline "None found"
end if

WshShell.Run "notepad C:\OrphServices.txt", 1,True
Set fso = Nothing
set Wshshell = Nothing

