Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Kill an application

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 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