473,396 Members | 1,755 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.

How to close another application when the main process has been killed?

I have a vb application(1) which is made to launch another software(2) with specified parameters, but i wanna keep my application opened as long as the 2nd one is opened too, and I also want to close the second one automatically if mine has been force closed by the user in windows taskmanager, on the desktop, or in any way.
So I need something which detects if windows is closing the program and kill the second application auto.

I would like to avoid the task manager block, because that isn't necessary for this i guess.

Any idea?
May 3 '11 #1
7 2475
!NoItAll
297 100+
You will need to look at the system.diagnostics

myProcesses = Process.GetProcessesByName("my application name")

You will need this call in a continuous running loop, possibly a secondary thread, in both applications. I would call this the suicide loop. If MyProcess no longer appears then you can end - or also call process.closemainwindow

To keep an application running as long as another specific application is also running
Expand|Select|Wrap|Line Numbers
  1. Dim myProcesses() As Process = Nothing
  2. myProcesses = Process.GetProcessesByName("process name I want to make sure is still there")
  3. If isNothing(myProcess) then
  4.      me.close
  5.      'end this application
  6. End if
  7.  
  8.  
  9.  
To kill another application before you close this one (call this on form.unload)
Expand|Select|Wrap|Line Numbers
  1. Dim myProcesses() As Process = Nothing
  2. Dim Instance as Process = Nothing
  3. myProcesses = Process.GetProcessesByName("process name I want to kill before I exit")
  4. For each Instance in myProcesses
  5.     process.CloseMainWindow()
  6. Next
  7.  
  8.  
Good luck..
May 3 '11 #2
Thank you for your fast feedback, but the second application is external, i can't edit the source of that, although i want to close that when my application shut down by taskmanager, is that possible?
May 4 '11 #3
!NoItAll
297 100+
- ok, it's sounding a little like you are writing a virus - or a program that acts like one. Tell us more information about your project please.
May 4 '11 #4
it's made for a game server, and i coded an "anti-hack" feature into it, which scan the unwanted applications periodically and close those, it concentrate to specified known hack applications which are in hide against anti virus softwares, so i need it running while the costumers playing, they have option to close my program anytime, but i want to close the game itself too in that case for better security.
yes it acts like a virus, like all anti-virus program in fact.
May 4 '11 #5
!NoItAll
297 100+
The info in the first post provides much of the code you need. If you specifically want to handle the case where your application is closed through the task manager you need to handle it in your FormClosing event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  2.     If e.CloseReason = CloseReason.TaskManagerClosing Then
  3.         Dim myProcesses() As Process = Nothing
  4.         Dim Instance as Process = Nothing
  5.         myProcesses = Process.GetProcessesByName("process name I want to kill before I exit")
  6.         For each Instance in myProcesses
  7.             process.CloseMainWindow()
  8.         Next
  9.     End if
  10.  
  11. End sub
  12.  
  13.  
Now this is all fine and good, but the other applications may well catch this close and throw it away, popup a message, or something else that foils your efforts...

Good luck.
May 4 '11 #6
I can't get it work, I've added and imported the System.Windows.Forms as reference, and I used this sub to avoid the errors in my application (I've used notepad for test):
Expand|Select|Wrap|Line Numbers
  1. Private Sub FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  2.         If e.CloseReason = CloseReason.TaskManagerClosing Then
  3.             Dim myProcesses() As Process = Nothing
  4.             Dim Instance As Process = Nothing
  5.             myProcesses = Process.GetProcessesByName("notepad")
  6.             For Each Instance In myProcesses
  7.                 Me.CloseMainWindow()
  8.             Next
  9.         End If
  10. End Sub
What's wrong with it? I'm using Windows 7 x64 if that's matter.
May 4 '11 #7
!NoItAll
297 100+
Ooops - sorry, I copied the wrong line. Don't use
me.closewindow. Instead use:

Instance.closemainwindow

I'm not near my original code - but I think that is correct...
May 4 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Markus Franz | last post by:
Hi. I created a little script: for currenturl in sys.argv: pid = os.fork() if pid == 0: signal.alarm(10) do_something() # placeholder for the download and print routine
3
by: carmen | last post by:
I need to launch application-2 from application-1 and close application-1. My code is CreateProcess ("app2",0,0,0,0,0,0,0,0,0); Application.Exit(); but application-1 is not terminate since I...
2
by: Tenacious | last post by:
I have been trying to run this program called mysqlbinlog.exe from my main c# application using the Process class(See example below). The way that mysqlbinlog functions is to read the first file in...
4
by: feng | last post by:
Hi, In our asp.net app, we need to capture the event when user close the browser window by clicking on the "x" button. But it doesn't seem to be as easy as it sound. Can someone show me how to...
5
by: Nicola Farina | last post by:
Hi all, I've a window form application with 3 forms. I want to catch the security exception when users run this application from a network share, thus I've made this code (I've notice that...
0
by: Srinivas | last post by:
I have a Process which lauches Internet Explorer.Using this process I keep changing the URL of the Browser based on certain user event. I intend to kill this Process and restart it when the Process...
9
by: Simon | last post by:
Hi, I have written an ActiveX object to resize images and upload them to a database, this all works fine but when I close internet explorer the process iexporer.exe is still running in my task...
0
by: hzgt9b | last post by:
Using VB .NET 2003, I am having problems with a windows application that I have written: Here's the situation. The application I created has a main form that has its TopMost property set to True...
3
by: rdemyan via AccessMonster.com | last post by:
Sometimes users (including myself) accidentally click on the application close icon in the application menu bar when they meant to just click on the 'X' for the form. Of course the app closes and...
7
by: dieter | last post by:
Hi, Overview ======= I'm doing some simple file manipulation work and the process gets "Killed" everytime I run it. No traceback, no segfault... just the word "Killed" in the bash shell and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.