Results 1 to 25 of 25

Thread: excute code after task is complete

  1. #1

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    excute code after task is complete

    hi all i have my program that creates a task that runs 10 min after the time its created and i was wondering how i could have the program monitor till when the task is run then excute the rest of the code

  2. #2

  3. #3

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    a task using the task scheduler that open up another program at the specified time

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: excute code after task is complete

    Try something like this...

    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2.    Private Sub Command1_Click()
    3.       'start code
    4.       Sleep (60000 * 10) 'in milli-seconds
    5.       'contnue code
    6.    End Sub

  5. #5

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: excute code after task is complete

    Are you Shelling that 'Task' (from your App). If so you may be able to use the WaitForInputIdle() API.

  7. #7

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    @RhinoBull no the program i'm opening is not my own

    @ Bruce Fox i'm creating the task by shelling the "At" command in command prompt

    now considering it was a windowed app could i just the program search for the hwnd of the window or the caption of the window?

  8. #8

  9. #9

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    ah i think i may have solved the problem i found an example on how to find part of the windows caption, there is one word that is always in the title bar of this window so i'll try it this way and see if it works if not i'll get back to you thanks for the help/suggestions so far guys

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: excute code after task is complete

    Wow, that is a risk if it is a common word and could appear in other titles

  11. #11

  12. #12

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    well in the title it shows the path of where it executes for example to use command prompt as an example it shows C:/Windows/System32/cmd.exe it shows it like that as well so i just search for the last part ( in this example cmd.exe)but as you guys are more experienced than i am i'm open for suggestions on better ways and thanks again

  13. #13

  14. #14

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    so what would be a better way? maybe searching for it by class ?

  15. #15

  16. #16
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: excute code after task is complete

    Or, perhaps you could create a wrapper for the other program and use that as your scheduled task instead. Then launch the other program from it using ShellAndWait or something similiar and notify your program when it is finished.

    Just a thought.

  17. #17
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: excute code after task is complete


  18. #18

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    the program that is ran by the task needs to stay open i want to check for when that program is open. i think i didnt explain my question well enough, so here's a basic run down of what the program should do : it creates a task using the "at" command that opens an external program in 10 min time from when it application is ran. when the task is completed and the other program is ran then my program should excute the rest of the code. ex: my program is run at 1:00 makes a task for notepad to run at 1:10pm thenit waits until notepad is run then it executes the rest of the code
    Last edited by dark_shadow; Jul 27th, 2006 at 09:43 PM.

  19. #19
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: excute code after task is complete

    You will to sit there and wait till that 3rd party app starts, and reqularily check for an instance of it, possibly using FindWindow etc.

  20. #20

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    so what would be the best method to do that ? look for the creation of the window? or is there an easier way?

  21. #21
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: excute code after task is complete

    You could place a Timer on the Form, and set it's interval to 1 minute. Then check for your spawned app (each minute) once identified, disable the Timer and get on with business.

  22. #22

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    ah so for as for the actual checking for the spawned app what would you suggest using ? looking for the window or looking for the application itself ? i was thinking the application itself acually

  23. #23
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: excute code after task is complete

    Outa curiosity, what is the name of this App?

    FindWindow... or equivalent (as it's Thread specific from memory). Is there a reason you couldn't use similar?

  24. #24
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: excute code after task is complete

    Window Title

    Module:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
    4. (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
    5. Private Declare Function EnumWindows Lib "user32.dll" _
    6. (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    7.  
    8. Private Target As String
    9. Private IsOpen As Boolean
    10.  
    11. Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
    12.     Dim buf As String * 256
    13.     Dim title As String
    14.     Dim length As Long
    15.     length = GetWindowText(app_hWnd, buf, Len(buf))
    16.     title = Left$(buf, length)
    17.     If InStr(1, title, Target, vbTextCompare) Or _
    18.         title Like Target Then
    19.         IsOpen = True
    20.     End If
    21.     EnumCallback = 1
    22. End Function
    23.  
    24. Public Function WindowExists(app_name As String) As Boolean
    25.     IsOpen = False
    26.     Target = app_name
    27.     EnumWindows AddressOf EnumCallback, 0
    28.     WindowExists = IsOpen
    29. End Function

    Form:
    VB Code:
    1. If WindowExists("Notepad") Then
    2.     Debug.Print "Notepad is open"
    3. Else
    4.     Debug.Print "Notepad is not open"
    5. End If

    Program EXE

    VB Code:
    1. Private Sub Command1_Click()
    2.     If ExeExists("Notepad.exe") Then
    3.         Debug.Print "Notepad is open"
    4.     Else
    5.         Debug.Print "Notepad is not open"
    6.     End If
    7. End Sub
    8.  
    9. Private Function ExeExists(app_exe As String) As Boolean
    10.     Dim Process As Object
    11.     For Each Process In GetObject("winmgmts:").ExecQuery _
    12.     ("Select Name from Win32_Process Where Name = '" & app_exe & "'")
    13.         ExeExists = True
    14.     Next
    15. End Function

  25. #25

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: excute code after task is complete

    @bruce Fox the app i'm trying to open is photoshop
    Last edited by dark_shadow; Jul 27th, 2006 at 11:11 PM.

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