Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21109

please help on check if process "notepad.exe" exist then wait to end

$
0
0
hello

i need help on check if process "notepad.exe" exists then wait "notepad.exe"to end

i use this code to wait but the codes to shell and wait


Code:

Option Explicit

Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF    'Wait forever
Const WAIT_OBJECT_0 = 0    'The state of the specified object is signaled.
Const WAIT_TIMEOUT = &H102 'The time-out interval elapsed, and the
                                  'object’s state is nonsignaled.

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long


Private Sub Form_Load()
Dim lPid As Long
Dim lHnd As Long
Dim lRet As Long

lPid = Shell("notepad.exe", vbNormalFocus) ' here i need to check if process "notepad.exe" exists then wait "notepad.exe"to end
If lPid <> 0 Then
    lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)      'Get a handle to the shelled process.
    If lHnd <> 0 Then                              'If successful, wait for the
        lRet = WaitForSingleObject(lHnd, INFINITE) ' application to end.
        CloseHandle (lHnd)                        'Close the handle.
    End If
    MsgBox "Just terminated.", vbInformation, "Shelled Application"
End If
End Sub

here anther code i use to check if process "notepad.exe" exist

Code:

Private Sub Form_Load()

If IsProcessRunning("notepad.exe") = True Then
    MsgBox "Process running!"
Else
    MsgBox "Process running!"
end if
end sub

module

Code:

'Check If Process Is Running
'Coded by stoopid/goodhigh

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, th32ProcessID As Long) As Long
Private Const TH32CS_SNAPPROCESS As Long = 2

Public Type PROCESSENTRY32
    dwSize As Long
    cntUseage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    swFlags As Long
    szExeFile As String * 1024
End Type

Public Function IsProcessRunning(Filename As String) As Boolean
    Dim hSnapShot As Long
    Dim pe32 As PROCESSENTRY32
    hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) 'create snapshot of process
    pe32.dwSize = Len(pe32) 'get size of processentry32
    Process32First hSnapShot, pe32 'get info about first process
    Do While Process32Next(hSnapShot, pe32) <> 0 'loop through all processes
        If InStr(1, LCase(pe32.szExeFile), LCase(Filename)) > 0 Then 'process found
            IsProcessRunning = True
        End If
    Loop
    CloseHandle (hSnapShot) 'close snapshot
End Function

can someone please fix it to check if process "notepad.exe" exist then wait "notepad.exe"to end not "sheel and wait"

thank you guys

Viewing all articles
Browse latest Browse all 21109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>