Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping a Process

Status
Not open for further replies.

KenFalk

Programmer
Apr 14, 2005
4
0
0
US
I have found that I can execute any file with the following code:

Dim oProcStart As New ProcessStartInfo
oProcStart.FileName = "C:\SomeFileOfUnknownType"
Process.Start(oProcStart)

Of course, the program that runs will be the program that is associated with the extension of the file.

At some latter point, I would like to request that the file that is opened be closed (the process be gracefully terminated).

How can I stop an external process that I have started?

-Ken
 
Try:

Dim aProcName As String = System.IO.Path.GetFileNameWithoutExtension("MyApp")

If Process.GetProcessesByName(aProcName).Length = 1 Then
 
Thanks for the reply,

When I start the process, I do not know the type of the file and therefore do not know the application used to open the file. What is "MyApp" supposed to be?

-Ken
 
MyApp is the name of the process you wish to kill, eg if you start msword.exe, replace MyApp with 'msword' You will be able to get this string that which you use to start the process originally
 
I started the process not with the name of an app but rather with the name of a file supplied by the user so I don't know the name of the app that is used unless I can retrieve it from code.

-Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top