|
-
Jul 27th, 2006, 06:14 PM
#1
Thread Starter
Fanatic Member
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
-
Jul 27th, 2006, 06:24 PM
#2
Re: excute code after task is complete
What type of "task" is it?
-
Jul 27th, 2006, 06:28 PM
#3
Thread Starter
Fanatic Member
Re: excute code after task is complete
a task using the task scheduler that open up another program at the specified time
-
Jul 27th, 2006, 06:35 PM
#4
Re: excute code after task is complete
Try something like this...
VB Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
'start code
Sleep (60000 * 10) 'in milli-seconds
'contnue code
End Sub
-
Jul 27th, 2006, 06:54 PM
#5
Re: excute code after task is complete
 Originally Posted by dark_shadow
a task using the task scheduler that open up another program at the specified time
Is it your program or not?
-
Jul 27th, 2006, 07:00 PM
#6
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.
-
Jul 27th, 2006, 07:54 PM
#7
Thread Starter
Fanatic Member
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?
-
Jul 27th, 2006, 08:12 PM
#8
Re: excute code after task is complete
You can certainly find window if you know its caption but if it's not consistent then you may have trouble looking for one.
-
Jul 27th, 2006, 08:18 PM
#9
Thread Starter
Fanatic Member
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
-
Jul 27th, 2006, 08:20 PM
#10
Re: excute code after task is complete
Wow, that is a risk if it is a common word and could appear in other titles
-
Jul 27th, 2006, 08:25 PM
#11
Re: excute code after task is complete
Exactly right Bruce: there could be many Notepad windows with similar captions "Notepad - nobody knows what..." and FindWindow will return first available. Then what...
-
Jul 27th, 2006, 08:27 PM
#12
Thread Starter
Fanatic Member
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
-
Jul 27th, 2006, 08:29 PM
#13
Re: excute code after task is complete
I hope it works for you but it's very risky to use partial caption you may end up executing second part of your main program too early.
-
Jul 27th, 2006, 08:30 PM
#14
Thread Starter
Fanatic Member
Re: excute code after task is complete
so what would be a better way? maybe searching for it by class ?
-
Jul 27th, 2006, 09:05 PM
#15
Re: excute code after task is complete
-
Jul 27th, 2006, 09:10 PM
#16
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.
-
Jul 27th, 2006, 09:31 PM
#17
Re: excute code after task is complete
-
Jul 27th, 2006, 09:34 PM
#18
Thread Starter
Fanatic Member
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.
-
Jul 27th, 2006, 09:43 PM
#19
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.
-
Jul 27th, 2006, 09:45 PM
#20
Thread Starter
Fanatic Member
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?
-
Jul 27th, 2006, 09:50 PM
#21
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.
-
Jul 27th, 2006, 10:06 PM
#22
Thread Starter
Fanatic Member
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
-
Jul 27th, 2006, 10:17 PM
#23
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?
-
Jul 27th, 2006, 10:25 PM
#24
PowerPoster
Re: excute code after task is complete
Window Title
Module:
VB Code:
Option Explicit
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Target As String
Private IsOpen As Boolean
Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long
length = GetWindowText(app_hWnd, buf, Len(buf))
title = Left$(buf, length)
If InStr(1, title, Target, vbTextCompare) Or _
title Like Target Then
IsOpen = True
End If
EnumCallback = 1
End Function
Public Function WindowExists(app_name As String) As Boolean
IsOpen = False
Target = app_name
EnumWindows AddressOf EnumCallback, 0
WindowExists = IsOpen
End Function
Form:
VB Code:
If WindowExists("Notepad") Then
Debug.Print "Notepad is open"
Else
Debug.Print "Notepad is not open"
End If
Program EXE
VB Code:
Private Sub Command1_Click()
If ExeExists("Notepad.exe") Then
Debug.Print "Notepad is open"
Else
Debug.Print "Notepad is not open"
End If
End Sub
Private Function ExeExists(app_exe As String) As Boolean
Dim Process As Object
For Each Process In GetObject("winmgmts:").ExecQuery _
("Select Name from Win32_Process Where Name = '" & app_exe & "'")
ExeExists = True
Next
End Function
-
Jul 27th, 2006, 10:34 PM
#25
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|