I can see whether or not a Service or a Windows program is runner through, the EnumServicesStatus, and FindWindow API's. However does anyone know of a way to find whether a process that is not a service and is not windowed is running.
The processes show up under the Task Managers Processes tab, an example of one would be. sqlservr.exe.
Here is the code that I use to test Window Programs. I imagine it would be similar for processes however I need something beside the FindWindow API to get the PID in order to use SendMessageTimeout.
[tt]
Public Function checkProgram(ByRef Program As String) As Long
On Error GoTo ErrorHandler
Dim myName As String
myName = "checkProgram(Program=" & Program & ""
Dim hWindow As Long
Dim lngResult As Long
Dim lngReturnValue As Long
hWindow = FindWindow(vbNullString, Program)
If hWindow = 0 Then
checkProgram = 998
Exit Function
End If
lngReturnValue = SendMessageTimeout(hWindow, WM_NULL, 0&, _
0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)
If lngReturnValue = 0 Then
checkProgram = 11
Exit Function
End If
'-1 response
DoEvents
hWindow = FindWindow(vbNullString, Program)
If IsWindow(hWindow) = 1 Then
checkProgram = 0
Else
checkProgram = 998
End If
Exit Function
ErrorHandler:
checkProgram = 1000
Call GlobalErr(m_strSource & myName & ": ERR#" & str(Err) & ", Desc:" & Err.Description)
End Function
[/tt] Craig, mailto:sander@cogeco.ca
Si hoc legere scis, nimis eruditionis habes
The processes show up under the Task Managers Processes tab, an example of one would be. sqlservr.exe.
Here is the code that I use to test Window Programs. I imagine it would be similar for processes however I need something beside the FindWindow API to get the PID in order to use SendMessageTimeout.
[tt]
Public Function checkProgram(ByRef Program As String) As Long
On Error GoTo ErrorHandler
Dim myName As String
myName = "checkProgram(Program=" & Program & ""
Dim hWindow As Long
Dim lngResult As Long
Dim lngReturnValue As Long
hWindow = FindWindow(vbNullString, Program)
If hWindow = 0 Then
checkProgram = 998
Exit Function
End If
lngReturnValue = SendMessageTimeout(hWindow, WM_NULL, 0&, _
0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)
If lngReturnValue = 0 Then
checkProgram = 11
Exit Function
End If
'-1 response
DoEvents
hWindow = FindWindow(vbNullString, Program)
If IsWindow(hWindow) = 1 Then
checkProgram = 0
Else
checkProgram = 998
End If
Exit Function
ErrorHandler:
checkProgram = 1000
Call GlobalErr(m_strSource & myName & ": ERR#" & str(Err) & ", Desc:" & Err.Description)
End Function
[/tt] Craig, mailto:sander@cogeco.ca
Si hoc legere scis, nimis eruditionis habes