1

I'm trying to make a .net 4.0 program which will get the filename of a PowerPoint Show (PPS) that is being viewed on the same machine. The purpose is to time how long a particular presentation takes to go through without any user action.

I've tried the following:

 oPPTApp = (PowerPoint.Application)System.Runtime.InteropServices.Marshal.
 GetActiveObject("PowerPoint.Application");
 string ppsname = oPPTApp.ActivePresentation.Name.ToLower();

The program runs minimized while the presentation is being viewed. Even while interacting with the PPS (scrolling through slides, clicking, etc), I get the following error from Microsoft.Office.Interop.PowerPoint._Application:

Application (unknown member) : Invalid request.  There is no active presentation.

After searching through http://support.microsoft.com/kb/285472, I tried adding:

oPPTApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

However, this started a new instance of PowerPoint, followed by the same error.

I'll also mention I'm using Microsoft PowerPoint 14.0 Object Library and the IOleMessageFilter error handler from here: http://msdn.microsoft.com/en-us/library/vstudio/ms228772(v=vs.110).aspx

Does ActivePresentation.Name not apply to PPS files? Is there a better way of getting the filename of an open PPS?

Alex
  • 689
  • 1
  • 8
  • 22
  • Use Task Manager, Processes tab. Check how many instances of powerpnt.exe are running. More than one is too many. – Hans Passant Oct 17 '14 at 18:22
  • I'm 100% certain only 1 instance is running while I try this without the oPPTApp.Visible line. Adding this line starts another instance of powerpnt.exe, but the "no active presentation" error occurs either way. – Alex Oct 17 '14 at 18:25
  • Why are you not following my recommendation? Tinkering with the Automation interface can leave extra copies of the process running that you cannot see but will be found by GetActiveObject(). – Hans Passant Oct 17 '14 at 18:28
  • It wasn't personal... and I absolutely did follow your advice, verified one instance of Powerpnt.exe *32 was running, and still got the error. Do you know of a better way of doing this? COM seems kind of unreliable now that you mentioned that. – Alex Oct 17 '14 at 18:35

1 Answers1

1

Why not use plain old System.Diagnostics.Process?

The following code will give you the name of the active window of all processes with a given friendly name (process name without extension; in your case "POWERPNT").

using System.Diagnostics;

public static IEnumerable<string> GetActiveMainWindowsTitle(string processName)
{
    var ps = Process.GetProcessesByName(processName);

    foreach (var p in ps)
        yield return p.MainWindowTitle;
}

The MainWindowTitle of a MS PowerPoint process is the name of the active presentation so if you are only looking for that info, this should do (you might need to clean the title a little if you are running, for example, a Home and Student version; usually there is a "non comercial use" tag on the main window title)

InBetween
  • 32,319
  • 3
  • 50
  • 90