473,396 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Kill a Process before it's finished running...

This is my problem... I have some code that starts a Process and
returns it to a variable... (prcBat)

At any time while that process is running... I want to be able to Kill
it by pressing a command button in the application.

So the code goes something like this:

psiBat = New ProcessStartInfo(arrRun.Item(0)(1))
psiBat.WindowStyle = ProcessWindowStyle.Hidden
psiBat.CreateNoWindow = True
prcBat = Process.Start(psiBat)
prcBat.WaitForExit()
And I have a command button that has this...

prcBat.Kill()
prcBat = Nothing
Now... my problem is this... some of the files that will be run by
this process are executables... when I start an exectable like so:

prcBat = Process.Start(psiBat)

....it immediately returns the variable prcBat and I can kill it right
away.
BUT... if the file I'm trying to run is a data file (for example, an
..xls file) then the line:

prcBat = Process.Start(psiBat)

....opens the Excel file (which contains its own code) BUT it doesn't
return the variable prcBat... it just waits at that line of code until
the Excel application is finished. (which makes the "WaitForExit" line
pretty much useless, since it waits for completion of the Process
before moving to the next line anyway)

So this does me no good at all, since I may want to kill the process
before it's finished. When I try to kill it using the command button,
if I'm running an executable, it works just fine, but if I ran an
Excel file, then it throws an exception because prcBat doesn't exist
yet (because the Start line hasn't returned the Process to the
variable yet).
So what do I do? How do I run a data file in a process and immediately
return the Process so I can kill it if needed? My real problem here is
with the inherent behavior in the Process.Start method. It doesn't
return its results to the variable immediately if it's running a data
file... it only does so if it's running an executable... which makes
this Method half-worthless. (what use is there returning the Process
to a variable if it won't happen until after the process is already
done running...???)
Please let me know of any ideas/suggestion you may have to get around
this. I may have to build my own function to replace the Process.Start
method... I can probably use a combination of the Shell command
(figure out which application opens the data file, if a data file is
specified) and pass the Process ID from the Shell command back to a
variable... but I'd rather find a more straightforward workaround if
possible.

WATYF
Nov 20 '05 #1
0 2155

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: John Lin | last post by:
Howdy, I want to know how to tell if a forked process is done. Actually, my real question is that I want to run a shell script inside of a python script, and after the shell script has...
6
by: Bob Swerdlow | last post by:
My application starts up a number of processes for various purposes using: self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py") and then shuts them down when appropriate with...
12
by: Steve | last post by:
AccessXP in Access2000 mode I have the following code outline in a standard module in MyDatabase.mdb --- Use CreateDatabase to create MyOtherDatabase.mdb Use two make table queries to create...
6
by: Matthew Wieder | last post by:
What permissions must a user have to be able to succesffuly execute a Process.Kill? I can run it with Admin privleges but not with regular user priveleges - I get an "Access is Denied." The...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
1
by: Daniel | last post by:
how to forcfully kill a running process by executable name with a .net application?
3
by: elrondrules | last post by:
Hi Am new to python and need your help!! this is my code snip. within my python script I have the following commands.. <snip> import os
4
by: Richard Rossel | last post by:
Hi Fellows, I have a problem with process termination. I have a python code that apache runs through a django interface. The code is very simple, first, it creates a process with the...
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.