Solved

Kill an application

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

10 Experts available now in Live!

Get 1:1 Help Now