Close exe from Window Close

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
10 posts Page 1 of 1
Contributors
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Close exe from Window Close
mikethedj4
When my form loads it runs AltWindowDrag. Which is what I want, but now what I wanna do is when it closes. How can I have it close AltWindowDrag as well?

This is what I'm using for it to run on form load...
Code: Select all
Process.Start(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
Last edited by mikethedj4 on Sun Jul 22, 2012 4:21 pm, edited 2 times in total.
Vikhedgehog
VIP - Donator
VIP - Donator
Posts: 812
Joined: Fri Nov 05, 2010 6:24 pm

Re: Run exe from Window Load
Vikhedgehog
Haven't been coding in VB for months, but i believe its Process.start("C:/Location of program")
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Re: Run exe from Window Load
mikethedj4
Vikhedgehog wrote:
Haven't been coding in VB for months, but i believe its Process.start("C:/Location of program")
ok thanks I updated the topic, cause now don't know how to close it lol
Vikhedgehog
VIP - Donator
VIP - Donator
Posts: 812
Joined: Fri Nov 05, 2010 6:24 pm

Re: Close exe from Window Close
Vikhedgehog
Some code I found on google :p


Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

For Each p As Process In pProcess
p.Kill()
Next

To close notepad
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Re: Close exe from Window Close
mikethedj4
Vikhedgehog wrote:
Some code I found on google :p

Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

For Each p As Process In pProcess
p.Kill()
Next

To close notepad
How would I use AltWindowDrag with that?
Code: Select all
Process.Start(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: Close exe from Window Close
Codex
I assume you would change notepad with AltWindowDrag so it becomes like this:
Code: Select all
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("AltWindowDrag")

For Each p As Process In pProcess
p.Kill()
Next
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Re: Close exe from Window Close
mikethedj4
Codex wrote:
I assume you would change notepad with AltWindowDrag so it becomes like this:
Code: Select all
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("AltWindowDrag")

For Each p As Process In pProcess
p.Kill()
Next
It's not that easy, it's a portable app, no installer, not in registry.

I tried...
Code: Select all
Dim pProcess() As Process = System.Diagnostics.Process.GetProcesses(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
but got the following error...
error.png
You do not have the required permissions to view the files attached to this post.
User avatar
lolxot
VIP - Donator
VIP - Donator
Posts: 155
Joined: Thu Apr 08, 2010 4:59 pm

Re: Close exe from Window Close
lolxot
try this:
Code: Select all
p = Process.GetProcessesByName("Process Name")
        If p.Count > 0 Then
            'Running
            Try
                Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("Process Name e.g. 'Firefox'")
                For Each p As Process In pProcess
                    p.Kill()
                Next
            Catch ex As Exception
                MessageBox.Show("Error!")
            End Try
        Else
            'Not Running
            MessageBox.Show("Exe is not running!")
        End If
Edit: I use this code for a game where you can start and stop a server!
Vikhedgehog
VIP - Donator
VIP - Donator
Posts: 812
Joined: Fri Nov 05, 2010 6:24 pm

Re: Close exe from Window Close
Vikhedgehog
mikethedj4 wrote:
Codex wrote:
I assume you would change notepad with AltWindowDrag so it becomes like this:
Code: Select all
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("AltWindowDrag")

For Each p As Process In pProcess
p.Kill()
Next
It's not that easy, it's a portable app, no installer, not in registry.

I tried...
Code: Select all
Dim pProcess() As Process = System.Diagnostics.Process.GetProcesses(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
but got the following error...
error.png
Might sound silly, but try to replace \ with / because it seems to be thinking that you try to connect to a remote computer.

Edit: Yah i tried it in explorer and it thinks that \\ is a computer, while // is a path.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Close exe from Window Close
mandai
It doesn't make much sense searching for the process after you have already got the value returned from Process.Start. You can use this:
Code: Select all
    Dim proc As Process

    Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click

        proc = Process.Start(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
    End Sub

    Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        If Not proc Is Nothing Then

            If Not proc.HasExited Then

                proc.Kill()
            End If
        End If
    End Sub
10 posts Page 1 of 1
Return to “Coding Help & Support”