Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
I am having a small problem, I run a program (By running VBA's "Shell
cmd) and this program will create a file so I wait for the fil creation on excel so I can continue working on it. Now the problem is that there is no telling how long the file will tak to be created therefore it makes it hard to set a TimeOut on th program so that after a certain time if no file found stop execution. What I wondered is, since the "Shell" cmd returns the Task ID, is ther any function that I can search if a process is running (By the Tas ID)? Or something similar? This way as soon as the task is not runnin anymore I can continue the program and if no file was found after tha I can stop the program without the user having to wait too long or th program stopping in the middle of the task execution. Best Regards Noo -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Hi Nook
There may be a solution using API functions. Do a Google search for API Functions. HTH Cordially Pascal "NooK " a écrit dans le message de ... I am having a small problem, I run a program (By running VBA's "Shell" cmd) and this program will create a file so I wait for the file creation on excel so I can continue working on it. Now the problem is that there is no telling how long the file will take to be created therefore it makes it hard to set a TimeOut on the program so that after a certain time if no file found stop execution. What I wondered is, since the "Shell" cmd returns the Task ID, is there any function that I can search if a process is running (By the Task ID)? Or something similar? This way as soon as the task is not running anymore I can continue the program and if no file was found after that I can stop the program without the user having to wait too long or the program stopping in the middle of the task execution. Best Regards NooK --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Nook
In addition have a look at www.allapi.net HTH Cordially Pascal "papou" a écrit dans le message de ... Hi Nook There may be a solution using API functions. Do a Google search for API Functions. HTH Cordially Pascal "NooK " a écrit dans le message de ... I am having a small problem, I run a program (By running VBA's "Shell" cmd) and this program will create a file so I wait for the file creation on excel so I can continue working on it. Now the problem is that there is no telling how long the file will take to be created therefore it makes it hard to set a TimeOut on the program so that after a certain time if no file found stop execution. What I wondered is, since the "Shell" cmd returns the Task ID, is there any function that I can search if a process is running (By the Task ID)? Or something similar? This way as soon as the task is not running anymore I can continue the program and if no file was found after that I can stop the program without the user having to wait too long or the program stopping in the middle of the task execution. Best Regards NooK --- Message posted from http://www.ExcelForum.com/ |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Try doing a Google Groups search on "ShellAndWait" or "ShellAndLoop".
Troy "NooK " wrote in message ... I am having a small problem, I run a program (By running VBA's "Shell" cmd) and this program will create a file so I wait for the file creation on excel so I can continue working on it. Now the problem is that there is no telling how long the file will take to be created therefore it makes it hard to set a TimeOut on the program so that after a certain time if no file found stop execution. What I wondered is, since the "Shell" cmd returns the Task ID, is there any function that I can search if a process is running (By the Task ID)? Or something similar? This way as soon as the task is not running anymore I can continue the program and if no file was found after that I can stop the program without the user having to wait too long or the program stopping in the middle of the task execution. Best Regards NooK --- Message posted from http://www.ExcelForum.com/ |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Thanks for the help (Nice website btw) but I am a bit confused.
couldn't find any function that will allow me to loop through th processes and check for their IDs, can you give me a hint or somewher to start at? Best Regards Noo -- Message posted from http://www.ExcelForum.com |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Nook
Thanks to TroyW and the valuable info found and Randy Birch's code, here's a sample code to acheive what you want (simply replace the Command1_Click sub to you existing macro where the shell command is executed) HTH Cordially Pascal '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' ' Copyright ©1996-2004 VBnet, Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" _ (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long Private Const PROCESS_QUERY_INFORMATION = &H400 Private Const STATUS_PENDING = &H103& Private Sub Command1_Click() RunShell "c:\windows\notepad.exe" End Sub Private Sub RunShell(cmdline As String) Dim hProcess As Long Dim ProcessId As Long Dim exitCode As Long ProcessId = Shell(cmdline, 1) hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId) Do Call GetExitCodeProcess(hProcess, exitCode) DoEvents Loop While exitCode = STATUS_PENDING Call CloseHandle(hProcess) MsgBox "The shelled process " & cmdline & " has ended." End Sub "NooK " a écrit dans le message de ... Thanks for the help (Nice website btw) but I am a bit confused. I couldn't find any function that will allow me to loop through the processes and check for their IDs, can you give me a hint or somewhere to start at? Best Regards NooK --- Message posted from http://www.ExcelForum.com/ |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Thanks, I've tried but the function gives me the msgbox straight awa
just as the program is starting. Maybe OpenProcess Is returning NULL? have tried another aproach using FindWindow an GetWindowThreadProcessId without success. Any other ideas? Best Regards Noo -- Message posted from http://www.ExcelForum.com |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Are you sure the process is NOT finished?
Cordially Pascal "NooK " a écrit dans le message de ... Thanks, I've tried but the function gives me the msgbox straight away just as the program is starting. Maybe OpenProcess Is returning NULL? I have tried another aproach using FindWindow and GetWindowThreadProcessId without success. Any other ideas? Best Regards NooK --- Message posted from http://www.ExcelForum.com/ |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for a Task on windows?
Yes because what happens is that I run a software which will filter
database and return me a dbf file. When I run the software (Process), small window shows the program running and what it is doing until i creates the dbf file and closes (The window closes), and I get th MsgBox right before the software window shows up, so Excel excutio halts but the software starts. Any idea? Best Regards Noo -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Windows in task bar in MS EXCEL 2007 | New Users to Excel | |||
Windows in Task bar in 2007 | Excel Discussion (Misc queries) | |||
Problem with Windows in Task Bar command | Excel Discussion (Misc queries) | |||
I check "windows in task bar", after restarting, it is no longer c | Excel Discussion (Misc queries) | |||
Excel Remains Active in Windows Task Manager | Excel Programming |