VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Is Process Running

James N. Wink  (2 Submissions)   Windows API Call/Explanation   Visual Basic 3.0   Advanced   Wed 3rd February 2021

This is do determine if any exe is already running. This handles the multithreading issues of NT, and it works on 95,98,NT. I got most of this straight from Microsoft, but have wrapped and cleaned it up alot.

Inputs
Pass it the EXE Name you want to know if it is running

Assumes
Test it with Notepad.exe or something first, and keep in mind that if you are debugging the application you want to use this with, that VB6.EXE is the process you are running, and until you compile and run your exe it will not see the app you are using.

Returns
True if process is running, else false.

API Declarations
Option Explicit
'Used to determine Process Information
Public Const PROCESS_QUERY_INFORMATION = 1024
Public Const PROCESS_VM_READ = 16
Public Const MAX_PATH = 260
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const SYNCHRONIZE = &H100000
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Const TH32CS_SNAPPROCESS = &H2&
Public Const hNull = 0
Public Const WIN95_System_Found = 1
Public Const WINNT_System_Found = 2
Public Const Default_Log_Size = 10000000
Public Const Default_Log_Days = 0
'Types Used by Win API's
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long ' This process
th32DefaultHeapID As Long
th32ModuleID As Long ' Associated exe
cntThreads As Long
th32ParentProcessID As Long ' This process's parent process
pcPriClassBase As Long ' Base priority of process threads
dwFlags As Long
szExeFile As String * 260 ' MAX_PATH
End Type
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long '1 = Windows 95.
'2 = Windows NT
szCSDVersion As String * 128
End Type
'Used to determine process information
Public Declare Function Process32First Lib "kernel32" ( _
ByVal hSnapshot As Long, _
lppe As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" ( _
ByVal hSnapshot As Long, _
lppe As PROCESSENTRY32) As Long
Public Declare Function CloseHandle Lib "Kernel32.dll" ( _
ByVal Handle As Long) As Long
Public Declare Function OpenProcess Lib "Kernel32.dll" ( _
ByVal dwDesiredAccessas As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcId As Long) As Long
Public Declare Function EnumProcesses Lib "psapi.dll" ( _
ByRef lpidProcess As Long, _
ByVal cb As Long, _
ByRef cbNeeded As Long) As Long
Public Declare Function GetModuleFileNameExA Lib "psapi.dll" ( _
ByVal hProcess As Long, _
ByVal hModule As Long, _
ByVal ModuleName As String, _
ByVal nSize As Long) As Long
Public Declare Function EnumProcessModules Lib "psapi.dll" ( _
ByVal hProcess As Long, _
ByRef lphModule As Long, _
ByVal cb As Long, _
ByRef cbNeeded As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" ( _
ByVal dwFlags As Long, _
ByVal th32ProcessID As Long) As Long
Public Declare Function GetVersionExA Lib "kernel32" ( _
lpVersionInformation As OSVERSIONINFO) As Integer

Rate Is Process Running (4(4 Vote))
Is Process Running.bas

Is Process Running Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters