How To Execute Files from Flash
This weekend I spent much time on creating a Flash projector for a menu based installation of Office and other programs. The screenshot below explains better what I was trying to accomplish, when someone clicks on the button named Engelsk (Engelsk = English) I wanted setup.exe to launch with a transform file applied to it.
I spent a lot of time playing around with the FSCommand EXEC, but it would not work. This was how you did it in previous versions of Flash. So after some trying and failing I started to google the problem and it turned out that the FSCommand EXEC is no longer working as it used to in Flash CS3.
So I needed to find another solution, I then came over a great tool called Proxy from Northcode that solved all my problems and the best thing: It’s free
Here is a summary from Nothcode’s blog about why this tool was developed and how it works;
A typical requirement you’ll run across when developing CD based Flash projects is the need to open documents from your Flash projector. You can use getURL to open most documents, but sometimes the document opens behind the projector. The EXEC fscommand could be used to launch a helper application, but unfortunately the EXEC fscommand doesn’t allow you to pass parameters to external applications so you have no way to tell the outside world which file you want to open.
You can thank the creators of the first Flash virus (SWF/LFM-926) for the fact that every version of the stand-alone Flash player since Flash MX has restricted the use of the EXEC command. This change made it impossible for anyone to create any new Flash based viruses, but it also crippled the Flash projector as a tool for legitimate users by instantly rendering many free projector extension tools useless.
There are four key restrictions that you have to keep in mind when working with the EXEC fscommand and standalone Flash projectors. (i) Executables you want to run via the EXEC fscommand have to be in a special sandboxed folder called fscommand in the same directory as the projector. (ii) You can’t specify a path in the EXEC command, just a filename. If the specified file is not found in the fscommand folder, it won’t run. (iii) The only argument allowed by the EXEC fscommand is a filename, there is no way to pass arguments to the executables that you want to run. (iv) You can’t use EXEC from an SWF file, it will only work from a projector (EXE). The last restriction doesn’t really concern us, but if you’re trying to test your EXEC calls, being aware of it will save you some frustration.
One additional restriction you will have to deal with is the fact that Flash 9 projectors can’t launch BAT files on Windows 2000, XP and Vista.
One solution to get around the limitations of the EXEC fscommand is to create one exectuable file for each file that you want to open, but what can you do if you don’t know how to make EXE files? Windows and Flash both consider a BAT file as an executable file so the easy solution is to create a BAT file for each file you want to open and EXEC the BAT file from Flash. You don’t need to be a BAT file wizard to do this, the simple one-liner below (let’s call it mydoc.bat) will do the trick:
That example assumes that both mydoc.bat and mydoc.pdf are in the fscommand folder. You can change the BAT file to launch the PDF file from anywhere you like, as long as you can create a valid path to the file. Now all you have to do is create a BAT file for every file you want to open and call it from Flash like this:
The only problem with this approach is that your user is going to see the ugly black DOS box appear every time they open a file. That’s where the proxy utility can help you create a more professional looking end product for your users. Proxy is able to launch BAT files and suppress the ugly DOS box.
usage: proxy.exe
When you run the proxy utility, the first thing it does is look at its own name, in this case proxy.exe. It then looks for a BAT file in the same directory with the same base name, i.e. proxy.bat, and runs that BAT file. If you rename the proxy utility to xyz.exe then the utility will look for and try to run xyz.bat. If a BAT file with the same name can’t be found, proxy will just fail silently.
By making copies of proxy.exe with different names and creating multiple BAT files you can run as many “hidden” BAT files as you need, neatly sidestepping the Flash limitation on passing parameters to external applications.
Here are step by step instructions to use the proxy utility to open a PDF file without the ugly DOS box.
- Create a BAT file called file1.bat that contains just the following line. This is a plain text file that you can create with notepad or your favorite text editor.
-
Put the BAT file in a folder called fscommand along with a copy of proxy.exe.
-
Rename the copy of proxy.exe to file1.exe (same base name as the BAT file you created).
-
Place your PDF document (called file1.pdf) in the fscommand folder with the BAT and EXE files. You don’t have to store the files you want to open in the fscommand folder, but for your first test this makes things easier.
-
Add the following command to your FLA where you want to open the PDF document (probably on a button release action).
Now put your Flash EXE and the fscommand folder on your desktop and run the Flash EXE. When the EXEC command is called your PDF document should open.
To read more about proxy or to download it you can go here.
Written by Odd-Magne Kristoffersen. Read more great feeds at is source WEBSITE
1 comment.
Read more articles on software.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article





















#1. February 8th, 2008, at 2:43 PM.
Is it possible to open a flash projector *exe within a *.swf? I need the flash projector to open an external app using facommand *.exe and *.bat.