Solved

Kill an application

Posted on 2011-02-28
4
387 Views
Last Modified: 2012-05-11
Hi,
I'm using VB.Net w/ Visual Studio 2005.

I'm trying to close a slideshow and then open it back up. I have some vba in the slideshow that executes on it's auto-open event, so when it opens back up it is updating the slides.

I tried to just kill the powerpoint.exe process, but that would close any slideshows that would be opened up on that pc and I don't really want to do that.

When I execute the code an InvalidOperationException msg is thrown. It says no process is associated with this object. I understand why this would happen initially since the process hasn't been opened yet the first time through. But if I continue through this msg and let the code open the slideshow then the next time through I would think the objprocess would have it's value. So what is causing this?

Thanks,
Dave
Private objProcess As System.Diagnostics.Process
Public Sub GetData()
        'close slide show.
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = "C:\Program Files\American Greetings\SlideShow\Sorter_Show_v5.0.pptm"
            objProcess.Kill()

        Catch
            MessageBox.Show("Could not stop process " & "C:\Program Files\American Greetings\SlideShow\Sorter_Show.ppt", "Error")
        End Try

        'Give powerpoint a second
        System.Threading.Thread.Sleep(1000)

        'Open the slideshow back up. VBA in the slideshow auto_open event will update slides.
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = "C:\Program Files\American Greetings\SlideShow\Sorter_Show_v5.0.pptm"
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
            objProcess.Start()
        Catch
            MessageBox.Show("Could not start process " & "C:\Program Files\American Greetings\SlideShow\Sorter_Show_v5.0.pptm", "Error")
        End Try
End Sub

Open in new window

0
Comment
Question by:coperations07
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:sindhuxyz
ID: 34999137
Use below:

-- Start notepad
System.Diagnostics.Process.Start("notepad")

-- Kill It!!
' Kill all notepad process
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

For Each p As Process In pProcess
p.Kill()
Next
0
 

Author Comment

by:coperations07
ID: 34999182
Thanks for that quick reply!

That shows how to kill all notepad processes.  If I had 2 notepad docs opened, say one is ME.txt and the other YOU.txt then how could I kill ME.txt without killing YOU.txt?
0
 
LVL 5

Accepted Solution

by:
sindhuxyz earned 350 total points
ID: 34999257


Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

        For Each p As Process In pProcess
            If p.MainWindowTitle = "ME.txt - Notepad" Then
                p.Kill()
            End If

        Next
0
 

Author Closing Comment

by:coperations07
ID: 35001728
Works like a charm. Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question