|
-
Apr 15th, 2010, 03:04 AM
#1
Thread Starter
Fanatic Member
End a process
Hi
I have a TextBox in which the user enters the filename of the file that he wants to display and a Button
I am using the process class to open files of any type(.xls,.pdf,.doc,.xml)...
when the user clicks on a button, it displays the filename mentioned in the textbox,and if he presses on the button for a second time and the textbox has changed,it should close the previous file and then open the new file.
how can I do that so only one file is opened?(If the first file is an excel and the second filename is a txt document, then I should close the excel file and then open the text document)
the code I am using is:
Code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Diagnostics
Namespace WindowsFormsApplication3
Public Partial Class Form1
Inherits Form
Private p As New Process()
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
p.StartInfo = New System.Diagnostics.ProcessStartInfo(textBox1.Text)
p.Start()
End Sub
End Class
End Namespace
-
Apr 15th, 2010, 03:29 AM
#2
Frenzied Member
Re: End a process
If processA, ProcessB is running then END ProcessC. If however ProcessA, and ProcessB are not running then ProcessC can stay active. This code is shown below.
Code:
Dim ProcessARunning as Boolean
Dim ProcessBRunning as Boolean
Dim AProcess As Process() = System.Diagnostics.Process.GetProcessesByName("ProgramA")
If AProcess.count <> 0 Then
ProcessARunning = True
Else
ProcessBRunning = False
End If
Dim BProcess As Process() = System.Diagnostics.Process.GetProcessesByName("ProgramB")
If BProcess.count <> 0 Then
ProcessBRunning = True
Else
ProcessBRunning = False
End If
If ProcessARunning = True and ProcessBRunning = True then
Dim CProcess() As Process = System.Diagnostics.Process.GetProcessesByName("ProgramC")
For Each Program As Process In CProcess
Program.Kill()
Next
If you find my reply helpful , then rate it
-
Apr 15th, 2010, 03:30 AM
#3
Frenzied Member
Re: End a process
To kill a process:
Code:
' Kill all notepad process
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")
For Each p As Process In pProcess
p.Kill()
Next
understand it and try to implement it in your project according to your need......
If you find my reply helpful , then rate it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|