Click here to Skip to main content
16,004,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a vbscript I execute from my C# application; it works fine, but how can I monitor the process to make sure it didn't hang? How do I know the vbscript finished and if it hangs, how can I kill it?
Thanks for any help.
Scott
C#
ProcessStartInfo si = new ProcessStartInfo();

si.FileName = "cscript.exe";
si.RedirectStandardOutput = true;                
si.Arguments = "Script.vbs";
si.UseShellExecute = false;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.CreateNoWindow = true;
Process p = Process.Start(si);

string searchResult = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Posted
Updated 24-Aug-10 0:47am
v2

You can use a timer to check if p has exited after a certain period of time, instead of calling WaitForExit. Actually, I think WaitForExit can take a timeout value.
 
Share this answer
 
Comments
scott radel 24-Aug-10 1:17am    
Yep looks like

Process.WaitForExit(int 32)

will do the trick.
thanks
sunjunfeng3 3-Sep-10 4:54am    
Reason for my vote of 1
sss
Can you give me an example of using the Win32 API instead of using CSCript.exe?

thanks

Scott
 
Share this answer
 
no recommend use "cscript.exe",it will start new proccess, you can't monitor other process informations more in different process, this need to call the WIN32 API to do, can't go do in .net framework
 
Share this answer
 
Comments
Toli Cuturicu 24-Aug-10 6:47am    
Reason for my vote of 1
no

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900