Visual Basic Development Bookmark and Share   
 Home > Visual Basic General > Shout down a process
 

Shout down a process

Hi Is there a way to shout down Excel

not as appilcation but as a process

And from Visul basic

It is because after i have shot down Excel 2007

it still runing as a process

Alvin

Alvin Kuiper  Friday, April 25, 2008 8:43 PM

Hi Alvin,

Here are some suggestions:

1. If you create an Excel application object in VB.NET, please remember to quit it.

Dim oExcel As Object = CreateObject("Excel.Application")

oExcel.Quit()

oExcel = Nothing

2. You can use Process.CloseMainWindow or Process.Kill to endExcel process.

Code Block

' Get all process whose name is Excel.exe.

Dim Proc() As Process = Process.GetProcessesByName("Excel")

For Each p As Process In Proc

p.CloseMainWindow()

' orp.Kill()

Next

Check this thread for detail:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2371540&SiteID=1

3. If the application processstill appears in Task ManagerProcesses listwhen you close your application, please check this thread for detailed solution:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2301913&SiteID=1

Best regards,

Martin

Martin Xie - MSFT  Monday, April 28, 2008 7:21 AM

Hi Alvin,

Here are some suggestions:

1. If you create an Excel application object in VB.NET, please remember to quit it.

Dim oExcel As Object = CreateObject("Excel.Application")

oExcel.Quit()

oExcel = Nothing

2. You can use Process.CloseMainWindow or Process.Kill to endExcel process.

Code Block

' Get all process whose name is Excel.exe.

Dim Proc() As Process = Process.GetProcessesByName("Excel")

For Each p As Process In Proc

p.CloseMainWindow()

' orp.Kill()

Next

Check this thread for detail:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2371540&SiteID=1

3. If the application processstill appears in Task ManagerProcesses listwhen you close your application, please check this thread for detailed solution:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2301913&SiteID=1

Best regards,

Martin

Martin Xie - MSFT  Monday, April 28, 2008 7:21 AM

Thanks

Its working with p.kill()

Alvin

Alvin Kuiper  Monday, April 28, 2008 8:41 PM
If two processes with the same name but a different file path are open can you isolate one from the other?
I seek not answers, but understanding, that I may not solve, but learn. What good is a fish without the skill to catch it?
CooperHawk  Friday, November 27, 2009 4:09 AM

Hi CooperHawk,

You can try retrieving additional property (e.g. Process.MainWindowTitle)value to distinguish these processes which havethe same name.


' Get all process whose name is Excel.exe.

Dim Proc() As Process = Process.GetProcessesByName("Excel")

For Each p As Process In Proc

If p.MainWindowTitle = "Book1.xls" Then
p.CloseMainWindow()

End If

Next

MainWindowTitle

Property: Gets the caption of the main window of the process.


You can investigate all properties of the Process class here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process_members.aspx


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Martin Xie - MSFT  Friday, November 27, 2009 1:23 PM
Maybe I should explain my situation. I have a program that won't have a different main window title. The program is a database management program that accesses information from the directory it exists in. But someone, theoretically, might have multiple database programs open. The only way to distinguish them would be by the file path, ex "C:\Program Files\Contact Manager\CMA.exe" vs. "C:\Documents and Settings\User\Application Data\Contact Manager\CMA.exe". I don't see file path or directory or location on the list you gave me :(
I seek not answers, but understanding, that I may not solve, but learn. What good is a fish without the skill to catch it?
CooperHawk  Friday, November 27, 2009 6:58 PM
is there a way to do what I want?
I seek not answers, but understanding, that I may not solve, but learn. What good is a fish without the skill to catch it?
CooperHawk  Saturday, November 28, 2009 10:20 PM
I don't think it matters how loud you shout , yell or scream it won't shutdown a process on your computer :-)
coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
Please format the code in your posts with the button . Makes it easier to read .
bdbodger  Saturday, November 28, 2009 10:40 PM
That was completely beside the point. I just want to know if there is a way to shut down a process based on the location of the exe file.
I seek not answers, but understanding, that I may not solve, but learn. What good is a fish without the skill to catch it?
CooperHawk  Monday, November 30, 2009 11:46 PM
I just want to know if there is a way to shut down a process based on the location of the exe file.

Hi CooperHawk,

I find the solution: Using Process.MainModule.FileName Property to get the full path to the process.
http://msdn.microsoft.com/en-us/library/system.diagnostics.processmodule.filename.aspx

' Get all process whose name is CMA.exe.

Dim Proc() As Process = Process.GetProcessesByName("CMA")

For Each p As Process In Proc

If p.MainModule.FileName = "C:\Program Files\Contact Manager\CMA.exe" Then
p.Kill()

End If

Next

Thank you All for your friendly help and support!

Best regards,
Martin Xie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Martin Xie - MSFT  23 hours 33 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Closing a VSTO Word template properly
• Creating .DLL Modules
• Listbox Search
• averaging numbers from an array
• The underlying connection was closed [FTP]
• DatetimePicker/Maxlegth Value Violation
• begginers help
• datagrid and external forms
• Linking two fields on form
• datagridview and checkbox