473,554 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ProcessStartInf o(arrRun.Item(0 )(1))
psiBat.WindowSt yle = ProcessWindowSt yle.Hidden
psiBat.CreateNo Window = True
prcBat = Process.Start(p siBat)
prcBat.WaitForE xit()
And I have a command button that has this...

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(p siBat)

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

prcBat = Process.Start(p siBat)

....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 "WaitForExi t" 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

Nov 20 '05 #1
0 2167

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

Similar topics

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 finished running, I want to do more stuff *condition* on the fact that the shell script has finished running, inside the same python script. The only...
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 os.kill(self.popen.pid, signal.SIGTERM) Everything works fine on MacOSX. However, I'm doing a port to Solaris (so I can run it on my web site) and find...
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 two tables in MyOtherDatabase.mdb Programatically zip MyOtherDatabase.mdb as MyZipfile.zip Kill "MyOtherDatabase.mdb" 'this is the actual line...
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 client should be able to run our software was a regular user, so what additional permission must I grant that user for this to work? thanks!
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 command button in the application. So the code goes something like this: psiBat = New ProcessStartInfo(arrRun.Item(0)(1)) psiBat.WindowStyle =...
by: Daniel | last post by:
how to forcfully kill a running process by executable name with a .net application?
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
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 subprocess.Popen call, and afterwards, (using a web request) the python code uses the PID of the previously created process(stored in a db) and kills it with an...
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 with weirdness going on with the server I am talking to. Anyhow, this locked up state happens once in a while (maybe once per day) and I can't...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.