Results 1 to 29 of 29

Thread: [RESOLVED] please help on check if process "notepad.exe" exist then wait to end

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

    Resolved [RESOLVED] please help on check if process "notepad.exe" exist then wait to end

    hello

    i need help on check if process "notepad.exe" running then wait "notepad.exe" until it is closed then

    Code:
        MsgBox "Just terminated.", vbInformation, "Shelled Application"
    End If
    End Sub
    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
    Last edited by sam-of; Nov 24th, 2013 at 09:35 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    i forgot to say i'm new here and it's my first post

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    is this not possible ?

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

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

    Check posts #12 or #13 in the Detect if program is not responding! thread.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by Nightwalker83 View Post
    Check posts #12 or #13 in the Detect if program is not responding! thread.
    i checked it out, it's not what i need bro

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

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

    You want to see if Notepad.exe is running and if it is you want to wait until it is closed then continue on in your app? You are going to need a timer which checks every so many nnn ms.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by jmsrickland View Post
    You want to see if Notepad.exe is running and if it is you want to wait until it is closed then continue on in your app? You are going to need a timer which checks every so many nnn ms.
    i don't thank so its that hard bro

    i use this code to open notepad.exe and wait until it is closed then

    Code:
        MsgBox "Just terminated.", vbInformation, "Shelled Application"
    End If
    End Sub
    the code is

    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
    i need to check if process "notepad.exe" running then wait
    Last edited by sam-of; Nov 24th, 2013 at 09:31 PM.

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

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

    I'm under the impression you do not want to Shell and Wait from your statement in post #1

    .....if process "notepad.exe" exist then wait "notepad.exe"to end not "shell and wait"

    What will the titlebar say on Notepad? Will it say Untitled - Notepad or something else?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

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

    @ Sam-of,

    You mean like this?

    Code:
    Option Explicit
    '
    ' Assumes a Timer Control is drawn on the Form named Timer1
    ' On clicking on the Form, this Program will start C:\Project1.Exe
    ' and monitor it until it terminates
    '
    Private Type STARTUPINFO
          cb As Long
          lpReserved As String
          lpDesktop As String
          lpTitle As String
          dwX As Long
          dwY As Long
          dwXSize As Long
          dwYSize As Long
          dwXCountChars As Long
          dwYCountChars As Long
          dwFillAttribute As Long
          dwFlags As Long
          wShowWindow As Integer
          cbReserved2 As Integer
          lpReserved2 As Long
          hStdInput As Long
          hStdOutput As Long
          hStdError As Long
    End Type
    
    Private Type PROCESS_INFORMATION
          hProcess As Long
          hThread As Long
          dwProcessId As Long
          dwThreadID As Long
    End Type
    
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
          hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
          lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
          lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
          ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
          lpStartupInfo As STARTUPINFO, lpProcessInformation As _
          PROCESS_INFORMATION) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" _
          (ByVal hObject As Long) As Long
    
    
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private proc As PROCESS_INFORMATION
    Private start As STARTUPINFO
    
    
    Private Function ExecCmd(cmdline$)
    Dim ret As Long
    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)
    ' Start the application:
    ret = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
             NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
    ExecCmd = ret
    End Function
    
    Sub Form_Click()
    Dim retval As Long
    Dim lngResult As Long
    Dim lngReturnValue As Long
    'Replace the path and name with that of the application you want to use
    retval = ExecCmd("C:\Project1.exe")
    Timer1.Enabled = True
    End Sub
    
    Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 1000
    End Sub
    
    Private Sub Timer1_Timer()
    Dim lngResult As Long
    Dim lngReturnValue As Long
    Dim ret As Long
    ret = WaitForSingleObject(proc.hProcess, 500)
    If ret = 0 Then
     'Do something here
        MsgBox "hello"
        Timer1.Enabled = False
    End If
    End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by Nightwalker83 View Post
    @ Sam-of,

    You mean like this?

    Code:
    Option Explicit
    '
    ' Assumes a Timer Control is drawn on the Form named Timer1
    ' On clicking on the Form, this Program will start C:\Project1.Exe
    ' and monitor it until it terminates
    '
    Private Type STARTUPINFO
          cb As Long
          lpReserved As String
          lpDesktop As String
          lpTitle As String
          dwX As Long
          dwY As Long
          dwXSize As Long
          dwYSize As Long
          dwXCountChars As Long
          dwYCountChars As Long
          dwFillAttribute As Long
          dwFlags As Long
          wShowWindow As Integer
          cbReserved2 As Integer
          lpReserved2 As Long
          hStdInput As Long
          hStdOutput As Long
          hStdError As Long
    End Type
    
    Private Type PROCESS_INFORMATION
          hProcess As Long
          hThread As Long
          dwProcessId As Long
          dwThreadID As Long
    End Type
    
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
          hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
          lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
          lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
          ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
          lpStartupInfo As STARTUPINFO, lpProcessInformation As _
          PROCESS_INFORMATION) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" _
          (ByVal hObject As Long) As Long
    
    
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private proc As PROCESS_INFORMATION
    Private start As STARTUPINFO
    
    
    Private Function ExecCmd(cmdline$)
    Dim ret As Long
    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)
    ' Start the application:
    ret = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
             NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
    ExecCmd = ret
    End Function
    
    Sub Form_Click()
    Dim retval As Long
    Dim lngResult As Long
    Dim lngReturnValue As Long
    'Replace the path and name with that of the application you want to use
    retval = ExecCmd("C:\Project1.exe")
    Timer1.Enabled = True
    End Sub
    
    Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 1000
    End Sub
    
    Private Sub Timer1_Timer()
    Dim lngResult As Long
    Dim lngReturnValue As Long
    Dim ret As Long
    ret = WaitForSingleObject(proc.hProcess, 500)
    If ret = 0 Then
     'Do something here
        MsgBox "hello"
        Timer1.Enabled = False
    End If
    End Sub
    thank you so much bro, its also to open and wait i will try edit codes to check if the process is running then wait till it closes i hope i can do it

  11. #11

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by jmsrickland View Post
    I'm under the impression you do not want to Shell and Wait from your statement in post #1

    .....if process "notepad.exe" exist then wait "notepad.exe"to end not "shell and wait"

    What will the titlebar say on Notepad? Will it say Untitled - Notepad or something else?
    sorry i mint check if process "notepad.exe" running then wait "notepad.exe" until it is closed

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    still i did not resolve the problem can someone help please on "check if process "notepad.exe" running then wait "notepad.exe" until it is closed "

  13. #13
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

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

    Quote Originally Posted by sam-of View Post
    thank you so much bro, its also to open and wait i will try edit codes to check if the process is running then wait till it closes i hope i can do it
    Not sure what you mean?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

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

    Duplicate threads merged.

    One topic, one thread please.

  15. #15

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by Nightwalker83 View Post
    Not sure what you mean?
    Code:
    Option Explicit
    '
    ' Assumes a Timer Control is drawn on the Form named Timer1
    ' On clicking on the Form, this Program will start C:\Project1.Exe
    ' and monitor it until it terminates
    '
    Private Type STARTUPINFO
          cb As Long
          lpReserved As String
          lpDesktop As String
          lpTitle As String
          dwX As Long
          dwY As Long
          dwXSize As Long
          dwYSize As Long
          dwXCountChars As Long
          dwYCountChars As Long
          dwFillAttribute As Long
          dwFlags As Long
          wShowWindow As Integer
          cbReserved2 As Integer
          lpReserved2 As Long
          hStdInput As Long
          hStdOutput As Long
          hStdError As Long
    End Type
    
    Private Type PROCESS_INFORMATION
          hProcess As Long
          hThread As Long
          dwProcessId As Long
          dwThreadID As Long
    End Type
    
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
          hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
          lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
          lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
          ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
          lpStartupInfo As STARTUPINFO, lpProcessInformation As _
          PROCESS_INFORMATION) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" _
          (ByVal hObject As Long) As Long
    
    
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private proc As PROCESS_INFORMATION
    Private start As STARTUPINFO
    
    
    Private Function ExecCmd(cmdline$)
    Dim ret As Long
    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)
    ' Start the application:
    ret = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
             NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
    ExecCmd = ret
    End Function
    
    Sub Form_Click()
    Dim retval As Long
    Dim lngResult As Long
    Dim lngReturnValue As Long
    'Replace the path and name with that of the application you want to use
    retval = ExecCmd("C:\Project1.exe")
    Timer1.Enabled = True
    End Sub
    
    Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 1000
    End Sub
    
    Private Sub Timer1_Timer()
    Dim lngResult As Long
    Dim lngReturnValue As Long
    Dim ret As Long
    ret = WaitForSingleObject(proc.hProcess, 500)
    If ret = 0 Then
     'Do something here
        MsgBox "hello"
        Timer1.Enabled = False
    End If
    End Sub
    this code to open C:\Project1.exe and wait until closed.

    what i need is to check if Project1.exe running then wait until it is closed

  16. #16
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

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

    You are asking how to do something and at the same time showing code that does what you are asking.

    I don't understand where you are coming from.

    First you say:
    this code to open C:\Project1.exe and wait until closed.

    OK, I run the code. It shells Project1.exe then when user closes Project1.exe the code will display Msgbox "hello"

    Second you say:
    what i need is to check if Project1.exe running then wait until it is closed

    That is exactly what the sample code does.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  17. #17
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

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

    Quote Originally Posted by sam-of View Post
    what i need is to check if Project1.exe running then wait until it is closed
    I don't think that is possible since you won't be monitoring the program before hand such as in the code above.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  18. #18

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by jmsrickland View Post
    You are asking how to do something and at the same time showing code that does what you are asking.

    I don't understand where you are coming from.

    First you say:
    this code to open C:\Project1.exe and wait until closed.

    OK, I run the code. It shells Project1.exe then when user closes Project1.exe the code will display Msgbox "hello"

    Second you say:
    what i need is to check if Project1.exe running then wait until it is closed

    That is exactly what the sample code does.
    sir the sample code to shell and wait i know, i don't want to shells Project1.exe.

    here is example sir

    http://rghost.net/50452947

  19. #19
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

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

    If you don't want to shell then you want to run Notepad outside of your program and wait till it is no longer running.

    I would think something like a Task Manager application would have the code you need. I have one. I'll take a look at it

    Doesn't that example you posted a link to give you what you need?

    Like I said post 6 you will need a timer
    Last edited by jmsrickland; Nov 25th, 2013 at 11:18 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  20. #20

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by jmsrickland View Post
    If you don't want to shell then you want to run Notepad outside of your program and wait till it is no longer running.
    yes sir that wait i need
    I would think something like a Task Manager application would have the code you need. I have one. I'll take a look at it

    Doesn't that example you posted a link to give you what you need?
    yes sir, but i need for wait code can you help me to add the wait code in the example i posted
    Like I said post 6 you will need a timer
    its OK i will add timer but wait is the wait code can you posted please
    Last edited by sam-of; Nov 25th, 2013 at 11:25 PM.

  21. #21
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

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

    How about a simple loop with a sleep statement inside where you check to see if the process exists, if yes then sleep 100 milliseconds or so and check again loop while true

  22. #22

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by DataMiser View Post
    How about a simple loop with a sleep statement inside where you check to see if the process exists, if yes then sleep 100 milliseconds or so and check again loop while true
    sir sleeping wont work, it has to be wait until it closes

  23. #23
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

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

    why not?

    Do while ProcessExist
    Sleep 100
    loop

    Would wait until the process is gone before it would execute the code following the loop

    you may need a doevents in there as well to keep the program from showing as not responding and allow the UI to refresh

    If that is not what you are trying to do then perhaps you should try an explain a bit more clearly.

  24. #24
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

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

    From what I can see, the code you need is in Post#1 'IsProcessRunning'
    Code:
    Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 100
    If Not IsProcessRunning("notepad.exe") Then
        Form2.Caption = "notepad is not running"
        Form2.Show
        Unload Me
    Else
        Me.Caption = "Waiting for notepad to terminate"
        Timer1.Enabled = True
    End If
    End Sub
    
    Private Sub Timer1_Timer()
    If Not IsProcessRunning("notepad.exe") Then
        Timer1.Enabled = False
        Form2.Caption = "notepad has terminated"
        Form2.Show
        Unload Me
    End If
    End Sub
    EDIT: BTW your code in Post#1
    Code:
    Private Sub Form_Load()
    
    If IsProcessRunning("notepad.exe") = True Then
        MsgBox "Process running!"
    Else
        MsgBox "Process running!"
    end if
    end sub
    has an obvious error.......
    Last edited by Doogle; Nov 26th, 2013 at 02:31 AM. Reason: spelling

  25. #25
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

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

    The problem is not so much waiting until the process stops as it is in getting the process in the first place. Because he does not want to shell then he needs to get a handle on an existing process (like it is done in task manager type applications) then using a timer check if process has closed (like when you refresh the task manager application). That should be fairly straight forward and not too complicated. There should be some task manager code in the Code Bank and I have one myself I just have to find it.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  26. #26
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

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

    From what I understand, OP doesn't need the PID or Handle - just an indication as to whether a particular Application is running or not and if it is running to 'wait' until it's terminated.

    The 'IsProcessRunning' routine takes a snap-shot of all running processes and returns True if the one being searched for is in that snap-shot, otherwise it returns False. My example just takes a snap-shot every 100 mS until 'IsProcessRunning' returns False.

    Of course, I may have got the wrong end of the stick as the actual problem is not very clearly defined.

    EDIT: The 'CreateToolhelp32Snapshot' API used by 'IsProcessingRunning' returns a structure that includes the Process ID. OP could use that and OpenProcess to get a Handle to it (given they have appropriate Security permissions), but I don't see why it's necessary.
    Last edited by Doogle; Nov 26th, 2013 at 02:50 AM.

  27. #27
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

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

    Then I don't see any problems for the OP.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  28. #28

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    61

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

    Quote Originally Posted by Doogle View Post
    From what I can see, the code you need is in Post#1 'IsProcessRunning'
    Code:
    Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 100
    If Not IsProcessRunning("notepad.exe") Then
        Form2.Caption = "notepad is not running"
        Form2.Show
        Unload Me
    Else
        Me.Caption = "Waiting for notepad to terminate"
        Timer1.Enabled = True
    End If
    End Sub
    
    Private Sub Timer1_Timer()
    If Not IsProcessRunning("notepad.exe") Then
        Timer1.Enabled = False
        Form2.Caption = "notepad has terminated"
        Form2.Show
        Unload Me
    End If
    End Sub
    EDIT: BTW your code in Post#1
    Code:
    Private Sub Form_Load()
    
    If IsProcessRunning("notepad.exe") = True Then
        MsgBox "Process running!"
    Else
        MsgBox "Process running!"
    end if
    end sub
    has an obvious error.......
    that's what i'm looking for , thank you sooooo much sir I really appreciate that

    thank you guys

    Reputation + for

    Doogle, Nightwalker83, jmsrickland

    close please
    Last edited by sam-of; Nov 26th, 2013 at 03:55 AM.

  29. #29
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

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

    Quote Originally Posted by sam-of View Post
    close please
    Just follow the instructions in my sig to resolve the thread.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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