PDA

View Full Version : Run a program from a PowerPoint slide (paging Morbo)


JimOfAllTrades
05-03-2007, 01:21 AM
I got some great PowerPoint advice from Morbo and several other dopers a couple of months back, and I’m hoping I can get some more help.

The basic question is this: What is the correct way to run another program by clicking a button on a PowerPoint slide?

Background: We’re running PowerPoint 2003 on Windows XP Pro.

We have several PowerPoints that all include a slide that links to a program we sell. At the appropriate time in the presentation the salesman can click on the button on the slide and start up the executable to give the audience a demonstration of the program.

The slide has a button graphic, and under the “Action Settings” for the button we have checked the “Run Program” option, and entered the drive, path, and program name.

The program is a standard windows executable which allows the user to enter data, perform some calculations, and print a few reports. There are a dozen or so small data files used by the program that must reside in the same folder as the executable.

Everything works fine as long as the PowerPoints and the executable are in the same folder.

But if the PowerPoint is in a different folder, the program starts when you click the button, but it can’t find the data files. The effect is the same as starting the program using a shortcut that has the target specified correctly, but has a blank “Start In” folder.

There is one other twist. If you open the PowerPoint, edit the “Action Settings” and re-select the program to run, then everything works fine until you close PowerPoint. But the next time you open PowerPoint and that presentation, it won’t work correctly until you go to that slide, edit the “Action Settings”, and re-select the program.

So what am I doing wrong? Any suggestions?

JimOfAllTrades
05-03-2007, 12:06 PM
Just bumping this up once for the daytime dopers.

Punoqllads
05-03-2007, 02:20 PM
What about creating a shortcut to your program and fill in its "Start In" folder with the relevant directory, and then having PowerPoint execute that?

Morbo
05-03-2007, 02:35 PM
Hmmm. Interesting. I'd be curious to know if Punoqllads suggestion works. I would also suggest maybe placing the executable code on an accessible intranet site and using a hyperlink to that site to execute it.

Other suggestions: Can this program be contained within a VBA container? You could write it as a .PPA (PowerPoint Add-In) and then you're guaranteed to auto-load it every time you load that presentation.

Or you could burn the PPT file and the folder that contains the EXE and data files to a CD or DVD and use that for your presentation - IOW forcing the PPT file and EXE to always reside in the same place.

(It's the data files that are the culprit here - this was a security issue - we debated totally removing the ability to run an EXE from within Slide Show | Run Program - there were too many exploit potentials in there but ultimately decided to limit its effectiveness, and this is an unfortunate trade-off.)

JimOfAllTrades
05-03-2007, 05:57 PM
What about creating a shortcut to your program and fill in its "Start In" folder with the relevant directory, and then having PowerPoint execute that?I had this on my list, and based on what I’ve seen, I think it will work, I'm going to try it later today.

The only reason I didn't want to do it is that one presenter is constantly creating new sub-folders for each school they go to, and copying the PowerPoints to the new folder, then making minor changes to customize the presentation. I was hoping to limit the stuff he had to copy to the PowerPoints themselves. But one more shortcut isn’t really a big deal.

Mostly I was curious why it works after you update the Action Settings on the slide, but only until you shut down PowerPoint.

Morbo
05-03-2007, 06:03 PM
Mostly I was curious why it works after you update the Action Settings on the slide, but only until you shut down PowerPoint.

I'm not reproing that one myself. Might've been fixed in a subsequent version but that issue isn't familiar to me.

jdc
05-03-2007, 06:10 PM
(It's the data files that are the culprit here - this was a security issue - we debated totally removing the ability to run an EXE from within Slide Show | Run Program - there were too many exploit potentials in there but ultimately decided to limit its effectiveness, and this is an unfortunate trade-off.)

"We" means you work for Microsoft?

Sounds like the feature did not have the restriction in some prior version of PPT?

Any reason there is no hint about this significant limitation on the "Action" setting screen or in the on line help for PPT ?

At least when I check my copy of Powerpoint 2003 neither the Help nor the Action screen clue you in that you have to put the PPT into the directory of the EXE.

And - if you set up an action link "run on mouse click" to a program that is not in the PPT directory, and you click during the show, do you get a dialog box with a clue why nothing happens? Not as I test the feature. You don't get any hint about why the program did not run.

jdc
05-03-2007, 06:23 PM
Well, my copy of PPT lets you run any EXE, with an appropriate warning before you click.

I had not filed the "Action" setting properly.

So as far as the "We" is concerned, I guess Morbo is talking about how he configures PPT security settings ?

??

nevermind.

JimOfAllTrades
05-03-2007, 07:38 PM
Hmmm. Interesting. I'd be curious to know if Punoqllads suggestion works.I’ll let you know!

I would also suggest maybe placing the executable code on an accessible intranet site and using a hyperlink to that site to execute it.Unfortunately, the presentations are often given in places that have no intranet or internet access.

Other suggestions: Can this program be contained within a VBA container? You could write it as a .PPA (PowerPoint Add-In) and then you're guaranteed to auto-load it every time you load that presentation.I don’t know the answer to this. The program is a standard 32 bit Windows executable. I have no experience with VBA, so I don’t know what’s involved. Any links you suggest to let me read up a bit and educate myself?

Or you could burn the PPT file and the folder that contains the EXE and data files to a CD or DVD and use that for your presentation - IOW forcing the PPT file and EXE to always reside in the same place.

(It's the data files that are the culprit here - this was a security issue - we debated totally removing the ability to run an EXE from within Slide Show | Run Program - there were too many exploit potentials in there but ultimately decided to limit its effectiveness, and this is an unfortunate trade-off.)This is a possibility, but I think in that case I’d just set up a process to copy the PowerPoints from whatever folder he was dealing with into a “current” folder where the exe and data files remained.

These are always executed on our laptops, they are never loaded onto the school’s system. So for us the security risk is minor, we not only created the PowerPoints, but I wrote the little database program.

This is more of an “ease of use” issue, and for my education. It seems like the way it is now should work. PowerPoint has the full path to the executable file, it’s just that it doesn’t set the current folder correctly before starting the exe. Or at least, not always.

Thanks for all the suggestions, and please post any others you think of. I’m always impressed by how people here are willing to take time, and sometimes considerable time, to help out with stuff like this. Many thanks!

JimOfAllTrades
05-03-2007, 08:31 PM
And - if you set up an action link "run on mouse click" to a program that is not in the PPT directory, and you click during the show, do you get a dialog box with a clue why nothing happens? Not as I test the feature. You don't get any hint about why the program did not run.I don’t have any problem running the executable if it’s in a different folder (and I see in subsequent post you don’t either), but I’ll elaborate on my situation a little just in case. :)

The problem I’m seeing is this: The program I’m running looks for the data files it needs in the “current” folder. Windows (and DOS before it) allows you to set the “current” folder to be a different than the folder than the program resides in. Since I load the data files in same folder as the executable, the current folder needs to be set to the folder with the executable before running.

The current folder is set by the “CD” command if you’re running the program from the command line, or the “start in” folder if you’re running the program from a shortcut. If you double click an executable in Windows Explorer, Explorer automatically sets the current folder to whichever folder the exe was in.

But PowerPoint doesn’t seem to be doing that, at least not consistently. If you open the PowerPoint and start the slideshow, go to the slide in question and click the button, the called program starts and runs from the other folder, but the current folder is still set to the folder the PowerPoint is in, so the called program can’t find the data files it needs.

Now end the slideshow, open the slide, edit the Action Settings for the button, and hit the browse button to re-select the executable you want to run. Restart the slideshow and everything works ok. But only until you end PowerPoint. The next time you open the presentation, it doesn’t work correctly until you open that slide, edit the Action settings, etc.

At least it’s not working for me, in PowerPoint 2003.

Now I could change the program to use a registry entry to set the path to the data files, I can create cmd files to set the current folder before loading the program, or other solutions. But every other Windows mechanism I’ve used to run programs either allows you to specifically set the current folder, or sets it automatically to match the executable folder.

I was convinced I was doing something wrong, but maybe not.

Anyway, thanks again for the suggestions. I’ll try creating a shortcut to put in the PowerPoint folder and call that instead of directly calling the program.

Any other suggestions welcome!

Punoqllads
05-03-2007, 08:37 PM
I don't know the internals of PowerPoint, but I'm guessing that your browsing the filesystem inside PowerPoint changes the current working directory (cwd) of your process, but the cwd is a per-process environment setting. The next time you run PowerPoint, it starts all over again.

JimOfAllTrades
05-03-2007, 11:03 PM
I don't know the internals of PowerPoint, but I'm guessing that your browsing the filesystem inside PowerPoint changes the current working directory (cwd) of your process, but the cwd is a per-process environment setting. The next time you run PowerPoint, it starts all over again.I suspect you’re exactly right.

Update: Linking to a shortcut which in turn runs the actual program seems to work, but there is an additional weirdness associated with that.

When you edit the action settings for the button and select the Browse button to select the shortcut, what gets selected isn’t the shortcut you clicked on, it’s the target of the shortcut.

For example, I create a shortcut named “Call FooBar”. The shortcut has c:\fb\foobar.exe as the target and c:\fb as the Start In folder.

I go to the PowerPoint, edit the Action Settings of the button, click Browse button next to the Run Program entry, navigate to c:\fb, select the “Call FooBar” shortcut and click Ok. Back in the Action Settings, the Run Program entry now shows c:\fb\foobar.exe instead of “Call FooBar”.

In order to get the shortcut in there instead of the program, I had to just type in the path and name of the shortcut, i.e., c:\fb\Call FooBar.lnk.

Anyway, this seems to be a simple workaround, and doesn’t even require copying the shortcut to the PowerPoint folder. All in all, a good solution, even if it took a while to work it out.

Thanks again everybody.

TimeWinder
05-03-2007, 11:59 PM
The program I’m running looks for the data files it needs in the “current” folder. Windows (and DOS before it) allows you to set the “current” folder to be a different than the folder than the program resides in. Since I load the data files in same folder as the executable, the current folder needs to be set to the folder with the executable before running.

You said earlier that you were selling the program. Does that mean you have access to its code? Relying on the current directory being set correctly is bad form.

GetModuleFileName() from any Win32 application will get the path to the application's directory, from which you can easily strip the .exe name and get the path. This will work regardless of the current directory. I'm sure there's a .NET equivalent if you need one. Even better, SHGetFolderPath() will give you the path to a number of common folders, including the current users's documents folder, or the Application Data folder, which would be better places to put these things, anyway. (This will become especially important in Vista if your application WRITES to these files -- normal users can't write to the Program Files directory.)

JimOfAllTrades
05-04-2007, 01:27 AM
You said earlier that you were selling the program. Does that mean you have access to its code?Yes, I wrote the program, and still have the full source code.
Relying on the current directory being set correctly is bad form.

GetModuleFileName() from any Win32 application will get the path to the application's directory, from which you can easily strip the .exe name and get the path. This will work regardless of the current directory. I'm sure there's a .NET equivalent if you need one.The language this is written in has an easy way to both get and set the current path, so it’s even easier than that.

Using the current directory was about the only choice given when this was originally written (in about 1993) and the resources we had available at the time. Since then we’ve massaged it several times, the last time in about 2003. Pretty much nothing got done that wasn’t absolutely needed, due to time and money constraints. In actual use the program is always launched by the shortcut or menu item, both of which explicitly set the working folder. There simply has never been any real need to do otherwise.

We’re currently planning a top to bottom re-write, which will add several features and bring many parts of the code up to current standards. Among the things that will be changed is the entire file handling process, which will allow many options beyond simply finding the current path.

Even better, SHGetFolderPath() will give you the path to a number of common folders, including the current users's documents folder, or the Application Data folder, which would be better places to put these things, anyway. (This will become especially important in Vista if your application WRITES to these files -- normal users can't write to the Program Files directory.)Yeah, my language of choice has high level commands for returning all these too.

We’re getting into IMHO or Great Debates territory here, but I disagree that these are necessarily better locations for the data files. Our new design supports this, and in fact the default will be the program installed under the Program Files folder, and the data in the user’s documents, but I don’t really care for it.

There is something to be said for a small footprint installation that does not write registry keys, installs everything in a single folder, and can be removed manually by a couple of simple deletes.

JimOfAllTrades
05-10-2007, 02:03 PM
Just to let those watching at home see how this came out.

I tested using the shortcut on my laptop the other day and it seemed to work. I’ve now put that solution on the actual “production” PC for the user who making the customized PowerPoints.

It does work, and except for the oddity that you can’t select the shortcut by browsing to it so you have to type it in (see my previous message on the subject), it’s working perfectly.

So thanks everybody, especially Morbo, for helping me out yet again.