Page 1 of 1
Close exe from Window Close
Posted: Sun Jul 22, 2012 3:24 pm
by 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 allProcess.Start(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
Re: Run exe from Window Load
Posted: Sun Jul 22, 2012 3:29 pm
by Vikhedgehog
Haven't been coding in VB for months, but i believe its Process.start("C:/Location of program")
Re: Run exe from Window Load
Posted: Sun Jul 22, 2012 4:10 pm
by 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
Re: Close exe from Window Close
Posted: Sun Jul 22, 2012 4:14 pm
by 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
Re: Close exe from Window Close
Posted: Sun Jul 22, 2012 4:39 pm
by 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 allProcess.Start(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
Re: Close exe from Window Close
Posted: Sun Jul 22, 2012 4:49 pm
by Codex
I assume you would change notepad with AltWindowDrag so it becomes like this:
Code: Select allDim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("AltWindowDrag")
For Each p As Process In pProcess
p.Kill()
Next
Re: Close exe from Window Close
Posted: Sun Jul 22, 2012 5:09 pm
by mikethedj4
Codex wrote:I assume you would change notepad with AltWindowDrag so it becomes like this:
Code: Select allDim 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 allDim pProcess() As Process = System.Diagnostics.Process.GetProcesses(Application.StartupPath & "\AltWindowDrag\AltWindowDrag.exe")
but got the following error...
error.png
Re: Close exe from Window Close
Posted: Sun Jul 22, 2012 7:29 pm
by lolxot
try this:
Code: Select allp = 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!
Re: Close exe from Window Close
Posted: Sun Jul 22, 2012 8:22 pm
by Vikhedgehog
mikethedj4 wrote:Codex wrote:I assume you would change notepad with AltWindowDrag so it becomes like this:
Code: Select allDim 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 allDim 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.
Re: Close exe from Window Close
Posted: Sun Jul 22, 2012 9:24 pm
by 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