Search for a process or service running on all remote computers.

I need to find all computers in my domain that are running a certain process.  I need it to scan and then display a list of all pc names with that process.  Anyway to do this with VB.Net or a vbscript?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi! First, you must reference System.DirectoryServices in your application. You may do like this
Imports System.DirectoryServices
Imports System.Collections.Generic

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnViewDetails.Click

        Dim directoryEntry As New DirectoryEntry("WinNT://domainName")
        Dim listOfComputer As New List(Of String)

        For Each de As DirectoryEntry In directoryEntry.Children
            If de.SchemaClassName = "Computer" Then

                For Each p As Process In Process.GetProcesses("\\" & de.Name)
                    'assuming you want to look for sqlserver process in each pc
                    'if found then you may add in list of computer
                    If p.ProcessName = "sqlserver" Then
                    End If

            End If

    End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

first i don't know exectly what drypz my friend wrote on but my vbscript code does this:

1. query active directory for all computer objects
2. ping to see if they online
3. check for possible permission issue
4 at last write to alog file if the process run

change in line 1 and 2 the process name and the log file path

strProcess = "outlook.exe"
strLog = "c:\log2.txt"


Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlog = objfso.CreateTextFile(strlog,True)
Set objConnection = CreateObject("ADODB.Connection")
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("defaultNamingContext")

Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://" & strDomain & "' Where objectClass='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
    strComputer = objRecordSet.Fields("Name").Value
If ping(strcomputer) Then
objlog.WriteLine strComputer & ": " & ProcessRun(strComputer)
objlog.writeline strComputer & " not reachable"
    End If

MsgBox "Done"

Function ProcessRun(strComputer)
On Error Resume Next
Set objRemote = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
If Err.Number <> 0 Then
ProcessRun = "No Permission on " & strComputer
On Error GoTo 0
Exit Function
End If
    Set colProcesses = objRemote.ExecQuery _ 
        ("SELECT * FROM Win32_Process " _ 
            & "WHERE Name = '" & strProcess & "'") 

If colProcesses.Count = 0 Then
ProcessRun = "Not Running"
ProcessRun = "Running"
End If
End Function

Function ping(strComputer)
wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"    
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")  
Set objPing = objWMIService.ExecQuery(wmiQuery)    
For Each objStatus in objPing      
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then          
ping = False 
ping = True 
End If  
End Function

Open in new window

kouts1Author Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.