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.
Printable View
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.
VB Code:
Option Explicit Private Declare Function CreateToolhelpSnapshot Lib "Kernel32" Alias "CreateToolhelp32Snapshot" _ (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function ProcessFirst Lib "Kernel32" _ Alias "Process32First" (ByVal hSnapShot As Long, uProcess As _ PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "Kernel32" _ Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As _ PROCESSENTRY32) As Long Private Declare Sub CloseHandle Lib "Kernel32" _ (ByVal hPass As Long) Private Const TH32CS_SNAPPROCESS As Long = 2& Private Const MAX_PATH As Integer = 260 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type Private Function IsSqlServerRunning() As Boolean Dim hSnapShot As Long Dim uProcess As PROCESSENTRY32 Dim r As Long hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) If hSnapShot = 0 Then Exit Function End If uProcess.dwSize = Len(uProcess) r = ProcessFirst(hSnapShot, uProcess) Do While r If InStr(LCase(uProcess.szExeFile), "sqlservr.exe") Then IsSqlServerRunning = True Exit Do End If r = ProcessNext(hSnapShot, uProcess) Loop Call CloseHandle(hSnapShot) End Function