clc;
workspace;
format long g;
format compact;
taskToLookFor = 'Excel.exe';
commandLine = sprintf('tasklist /FI "IMAGENAME eq %s"', taskToLookFor)
[status result] = system(commandLine)
itIsRunning = strfind(lower(result), lower(taskToLookFor))
if itIsRunning
message = sprintf('%s is running.', taskToLookFor);
uiwait(helpdlg(message));
else
message = sprintf('%s is not running.', taskToLookFor);
uiwait(helpdlg(message));
return;
end
message = sprintf('Do you want to monitor it until it finishes?');
button = questdlg(message, 'Wait for shutdown?', 'Yes', 'No', 'Yes');
drawnow;
if strcmpi(button, 'No')
return;
end
maxChecks = 10;
numberOfChecks = 1;
while itIsRunning && numberOfChecks < maxChecks
[status result] = system(commandLine);
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;
end
pause(1);
numberOfChecks = numberOfChecks + 1;
end
msgbox('Done with demo!');
Best Answer