Solved

Kill an application

Posted on 2011-02-28
4
385 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now