How to close other application on my computer?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 909 Views - Last Post: 19 June 2013 - 12:25 PM Rate Topic: -----

#1 scdogas321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-February 13

How to close other application on my computer?

Posted 19 June 2013 - 10:37 AM

Hi everyone, I really need your help. I used Shell("") to open a application (For Ex. Google Chrome). How can I close Google Chrome with VB.net too, like I opened it?
Thanks :).
Is This A Good Question/Topic? 0
  • +

Replies To: How to close other application on my computer?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8890
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: How to close other application on my computer?

Posted 19 June 2013 - 10:53 AM

Use the System.Diagnostics.Process.GetProcessesByName to get all the processes listed.. and then Process.Kill on the process object you want gone.

Example:

        '-- get a collection of processes running
        Dim foo() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses

        '-- go through each one looking for the internet explorer name
        For Each temp As Diagnostics.Process In foo
            If temp.ProcessName = "iexplore" Then
                temp.Kill() '-- if I find it, kill it.
                Exit For '-- exit the for loop

            End If
        Next

Was This Post Helpful? 1
  • +
  • -

#3 scdogas321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-February 13

Re: How to close other application on my computer?

Posted 19 June 2013 - 11:22 AM

I tried it but it's doing nothing, I mean when I need to use that commands nothing happens. I'm using Windows 8. Maybe there is another code for that?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8890
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: How to close other application on my computer?

Posted 19 June 2013 - 11:25 AM

I have no idea what code you are using, or what you are trying to close. Put a breakpoint at the start of the for loop and see what is inside of 'foo'.. maybe you have the name wrong.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3175
  • View blog
  • Posts: 10,625
  • Joined: 12-December 12

Re: How to close other application on my computer?

Posted 19 June 2013 - 11:28 AM

I thought trying CloseMainWindow() first rather than Kill would be safer, but I think this requires a little testing, particularly if there is more than one tab open in IE. (IE is a recalcitrant beast!)

        For Each temp As Diagnostics.Process In foo
            'Debug.Print(temp.MainWindowTitle)
            If temp.ProcessName = "iexplore" Then
                If Not temp.CloseMainWindow() Then
                    temp.Kill() '-- if I find it, kill it.
                End If
                Exit For '-- exit the for loop
            End If
        Next

Maybe the process is not named "iexplore" in Windows 8? Try printing out the process names first.

This post has been edited by andrewsw: 19 June 2013 - 11:50 AM

Was This Post Helpful? 0
  • +
  • -

#6 scdogas321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-February 13

Re: How to close other application on my computer?

Posted 19 June 2013 - 11:53 AM

I tried with notepad, I opened task manager and the name was: notepad.exe, I wrote that in
temp.ProcessName = "notepad.exe"
and it's wasn't responding... By the way i'm using Speech Recognision.
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3175
  • View blog
  • Posts: 10,625
  • Joined: 12-December 12

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:00 PM

Print out the process-names within the loop. If you are running this as a Console App, then use Console.WriteLine(). Otherwise, you could use Debug.Print() and read the information in the Immediate window.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8890
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:01 PM

Quote

I tried with notepad, I opened task manager and the name was: notepad.exe,

So funny story - that's not its process name. As I said - put a breakpoint *BEFORE* the for loop and examine what the contents of 'foo' are.. and you will see the name is similar, but not that.
Was This Post Helpful? 0
  • +
  • -

#9 scdogas321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-February 13

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:02 PM

I tried [code]temp.ProcessName = "notepad"[/cod] too.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8890
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:03 PM

Take Andrew's suggestion and list out all the processes in the debug or console window.
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3175
  • View blog
  • Posts: 10,625
  • Joined: 12-December 12

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:03 PM

When I have Notepad running its ProcessName is "notepad", not "notepad.exe". (What made you think it was notepad.exe?)
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8890
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:08 PM

@andrew - because in the task manager that's what it shows.
Was This Post Helpful? 0
  • +
  • -

#13 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3175
  • View blog
  • Posts: 10,625
  • Joined: 12-December 12

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:15 PM

View Postmodi123_1, on 19 June 2013 - 07:08 PM, said:

@andrew - because in the task manager that's what it shows.

Mm, I'm using Windows XP and I can't see the process name; it's not in the list of available columns. There is an 'Image Name' which is 'notepad.exe'(?).

This post has been edited by andrewsw: 19 June 2013 - 12:16 PM

Was This Post Helpful? 0
  • +
  • -

#14 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8890
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:16 PM

Yeah I think s/he was going off of that column.
Was This Post Helpful? 0
  • +
  • -

#15 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3175
  • View blog
  • Posts: 10,625
  • Joined: 12-December 12

Re: How to close other application on my computer?

Posted 19 June 2013 - 12:21 PM

View Postmodi123_1, on 19 June 2013 - 07:16 PM, said:

Yeah I think s/he was going off of that column.

Yes, sorry, I was being too obtuse ;) - that is what I was hinting at, and why I was suggesting that he/she print the names. Andy.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2