How can I check if a PowerPoint slideshow is running?

3 次查看(过去 30 天)
I have made a script that adds a slide to a PowerPoint Presentation by using the ActiveX session. It then runs a slideshow by using GotoSlide()
I want to know how I can use MATLAB to find out whether there is a PowerPoint slideshow running or not, because the next action is based on if the slideshow is closed by the Esc-key

回答(1 个)

Image Analyst
Image Analyst 2013-6-3
You're in luck. I just happen to have the code, though I've just tested it on Powerpoint, not the slide show version of it. You can find the process name by typing control-shift-Esc.
% find_running_process.m
% Finds out if a process is running.
% Let's you monitor the process until it shutsdown.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
% Execute the system command
% tasklist /FI "IMAGENAME eq Powerpnt.exe"
% First define the name of the program we're looking for.
% You can run it then execute "tasklist" in a
% CMD console window if you don't know the exact name.
taskToLookFor = 'Powerpnt.exe';
% Now make up the command line with the proper argument
% that will find only the process we are looking for.
commandLine = sprintf('tasklist /FI "IMAGENAME eq %s"', taskToLookFor)
% Now execute that command line and accept the result into "result".
[status result] = system(commandLine)
% Look for our program's name in the result variable.
itIsRunning = strfind(lower(result), lower(taskToLookFor))
if itIsRunning
message = sprintf('%s is running.', taskToLookFor);
else
message = sprintf('%s is not running.', taskToLookFor);
end
uiwait(helpdlg(message));
message = sprintf('Do you want to monitor it until it finishes?');
button = questdlg(message, 'Wait for shutdown?', 'Yes', 'No', 'Yes');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'No')
return;
end
% Go into a loop waiting for it to finish.
maxChecks = 10; % Max seconds to wait before exiting - a failsafe.
numberOfChecks = 1;
while itIsRunning && numberOfChecks < maxChecks
% Now execute that command line and accept the result into "result".
[status result] = system(commandLine);
% Look for our program's name in the result variable.
itIsRunning = strfind(lower(result), lower(taskToLookFor));
if itIsRunning
message = sprintf('%s is still running after %d seconds.\n',...
taskToLookFor, numberOfChecks);
fprintf('%s', message);
else
message = sprintf('%s is not running anymore.\n', taskToLookFor);
fprintf('%s', message);
uiwait(helpdlg(message));
break; % Exit loop.
end
pause(1); % Wait a second before checking again.
numberOfChecks = numberOfChecks + 1;
end
msgbox('Done with demo!');
  2 个评论
Michael
Michael 2013-6-3
Your code works fine, but unfortunately the process name for the powerpoint slideshow is still 'Powerpnt.exe'. So MATLAB cannot distinguish between the two of them.
I tried 'pptShow.View.State', which gave me 'ppSlideShowRunning' when the slideshow was running, but when I closed the slideshow it displayed an error message:
SlideShowWindow.View : Object does not exist
Is there any way to use the ActiveX session to find the state of the slideshow? Maybe by checking if the object 'SlideShowWindow.View' exists? I have tried exist('SlideShowWindow.View') and exist('SlideShowWindow') without any luck. Both of them returned 0.
Michael
Michael 2013-6-3
编辑:Michael 2013-6-3
I think I got it. I used almost all the possibilities for ppt.(...).get to find it
'ppt.Active' shows if the presentation window is active.
strcmp(ppt.Active,'msoTrue')
will give me 0 if the slideshow is running and 1 if the slideshow is not running (the presentation window is active)

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by