Results 1 to 2 of 2

Thread: How to detect a process

  1. #1

    Thread Starter
    Lively Member satti charvak's Avatar
    Join Date
    Apr 2001
    Location
    noida, india
    Posts
    90

    How to detect a process

    Hi All,
    I want to know, say, if sqlserver is running or not. It can be seen in the Process in the task manager (win2k) but I want to detect it using VB6.0. How can this be done. Please advise.

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function CreateToolhelpSnapshot Lib "Kernel32" Alias "CreateToolhelp32Snapshot" _
    4. (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    5.  
    6. Private Declare Function ProcessFirst Lib "Kernel32" _
    7. Alias "Process32First" (ByVal hSnapShot As Long, uProcess As _
    8. PROCESSENTRY32) As Long
    9.  
    10. Private Declare Function ProcessNext Lib "Kernel32" _
    11. Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As _
    12. PROCESSENTRY32) As Long
    13.  
    14. Private Declare Sub CloseHandle Lib "Kernel32" _
    15. (ByVal hPass As Long)
    16.  
    17. Private Const TH32CS_SNAPPROCESS As Long = 2&
    18. Private Const MAX_PATH As Integer = 260
    19.  
    20. Private Type PROCESSENTRY32
    21.   dwSize As Long
    22.   cntUsage As Long
    23.   th32ProcessID As Long
    24.   th32DefaultHeapID As Long
    25.   th32ModuleID As Long
    26.   cntThreads As Long
    27.   th32ParentProcessID As Long
    28.   pcPriClassBase As Long
    29.   dwFlags As Long
    30.   szExeFile As String * MAX_PATH
    31. End Type
    32. Private Function IsSqlServerRunning() As Boolean
    33.  
    34.     Dim hSnapShot As Long
    35.     Dim uProcess As PROCESSENTRY32
    36.     Dim r As Long
    37.  
    38.     hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    39.  
    40.     If hSnapShot = 0 Then
    41.         Exit Function
    42.     End If
    43.  
    44.     uProcess.dwSize = Len(uProcess)
    45.  
    46.     r = ProcessFirst(hSnapShot, uProcess)
    47.  
    48.     Do While r
    49.         If InStr(LCase(uProcess.szExeFile), "sqlservr.exe") Then
    50.            IsSqlServerRunning = True
    51.            Exit Do
    52.         End If
    53.         r = ProcessNext(hSnapShot, uProcess)
    54.     Loop
    55.  
    56.     Call CloseHandle(hSnapShot)
    57.  
    58. End Function
    oh1mie/Vic


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width