473,326 Members | 2,125 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,326 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 907

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...
3
by: Alex Hunsley | last post by:
I'm running a monitoring script under linux written in python. It's nohup'ed so that I can log out and it will continue running happily and so on, but sometimes I need to kill the script before...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.