?
Solved

Kill an application

Posted on 2011-02-28
4
Medium Priority
?
389 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 1400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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