coperations07
asked on
Kill an application
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
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
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works like a charm. Thanks!
-- Start notepad
System.Diagnostics.Process
-- Kill It!!
' Kill all notepad process
Dim pProcess() As Process = System.Diagnostics.Process
For Each p As Process In pProcess
p.Kill()
Next