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?

Thanks,
Kouts1
kouts1Asked:
Who is Participating?
 
drypzCommented:
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
                        listOfComputer.Add(de.Name)
                    End If
                Next

            End If
        Next

    End Sub

Open in new window

0
 
yehudahaCommented:
hey

first i don't know exectly what drypz my friend wrote on vb.net 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"

Const ADS_SCOPE_SUBTREE = 2

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
objRecordSet.MoveFirst

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

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"
Else
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 
Else          
ping = True 
End If  
Next 
End Function

Open in new window

0
 
kouts1Author Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.