Conquering FSCommand EXEC Part 1 : Proxy
 Posted on Tue Aug 7 2007 in Tools by Tim

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.

Update 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.

Important If you use SWF Studio then you don't need to read any further. SWF Studio still supports the Flash EXEC FSCommand but the limitations have been removed. Your SWF Studio projectors will be able to pass arguments to external applications and you won't have to put the executables you want to run in the fscommand sandbox folder. SWF Studio extends Flash with new commands like ssCore.Shell.execute and ssCore.Shell.open that make the EXEC fscommand obsolete and give you an unprecedented amount of control over your external applications and documents.

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:

start mydoc.pdf

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:

fscommand("exec", "mydoc.bat");

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.

start file1.pdf

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).

fscommand("exec", "file1.exe");

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.

The example.zip contains the source for a simple Flash MX projector (projector.fla), a compiled version of the projector (projector.exe) and an fscommand folder with a copy of the proxy utility (renamed to test.exe), the BAT file that the proxy utility will launch (test.bat) and a PDF file (test.pdf) that will be opened when the BAT file is run. Download the example to see the proxy utility in action.



Version: 3.0
Released: August 13, 2007
Download: proxy.exe (52KB)

This utility has been around for many years now and the Standalone and Applications forum that I moderate at FlashKit is home to a few long running discussions about problems other people have encountered and how the proxy utility has helped them. Definitely worth a read.

Comments

Hi ! Many thanks for your .exe. You saved me! I coudn't fix this fp9 projector problem with fscommand exec.

Best regards

Jerome
Posted by Jerome Labarbe on 30 Aug 2007 at 11:52am
YOU ARE MY IDOL

i was really frustrated untill i reach your blog, now my demo disc run perfectly thank you very mucho
Posted by Demonh8 on 5 Sep 2007 at 5:18pm
If it wasn't for people like you, we would scratch the walls with frustration whenever a company like Adobe screwed something up :)

Keep up the great work!
Posted by Peter Kalman on 10 Sep 2007 at 7:52am
You are a life saver !!!

I owe you my life. Nothing like waiting until the night before to test an extremely important part of the project. I would have paid a lot of money for that. Thank you, thank you, thank you.

"Sir here is a check with my name on it, write any amount on it and I will pay it " -Peter Griffin
Posted by Daniel Smith on 13 Sep 2007 at 11:46pm
Thanks, thanks....From me (the developer), my magazine director and all our readers.
Posted by Carlos López-Plandolit on 14 Sep 2007 at 9:24am
Maybe the only document to get over this annoying limitations.
Great instructions mate, thanx a bunch!
Posted by Seyfi Cem Baskýn on 17 Sep 2007 at 5:17am
What do you want ?, just name it. You saved my bacon on a very important job I have been struggling with. Thank You.
Posted by Andrew Keet on 17 Sep 2007 at 2:30pm
Agreed. This is an awesome script you have compiled. This has definitely saved my hide as well in creating a hybrid CD. Thank You! does not seem enough.

... and the link to the forum has helped a lot with issues I ran into.
Posted by Amy on 18 Sep 2007 at 12:27pm
Thanx man ur job is great! long life with scripting and saving ppl ;)

cheers
Posted by Paco on 19 Sep 2007 at 4:30am
You have no idea how grateful i am... you exes really helped me with that presentation...
Thanks a lot
Posted by verdesoto on 27 Sep 2007 at 5:13pm
THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!! THANK YOU!!!!!
Posted by Tom on 4 Oct 2007 at 10:40pm
Excelente! No más problemas. Gracias amigo!
Posted by Bambino on 9 Oct 2007 at 6:26pm
Dude, i think i love u!
Posted by David on 13 Oct 2007 at 1:30am
Thanks for this awesome tutorial you ROCK
Posted by The Designer on 15 Oct 2007 at 3:34pm
super duper dooooo!!

agr8 man! you did it
Posted by Muthu on 25 Oct 2007 at 4:35am
Such an annoying problem in the first place... Thank you so much for providing a solution!
Posted by Kayvan on 25 Oct 2007 at 10:48am
HELL YES! I'd love to buy you a beer, or whatever your drink of choice. I had a CD project going out today and my external files werent working. This saved my butt!
Posted by Josh on 29 Oct 2007 at 5:03pm
I will be eternally grateful!!! THANKS!!! Salú!!
Posted by marisa on 31 Oct 2007 at 6:43pm
OH MY GOD!
I´m From Brasil, and i was searching how to open pdf in .exe, then I saw: It doesn´t works in CS3!
Then I enter here and there it is!!

THANK YOU! You ROCK!You Save me!

Best Regards!!!
Posted by Beno Netto on 2 Nov 2007 at 7:42pm
you have saved my insanity!!
Posted by Kirsty on 5 Nov 2007 at 9:34am
you beauty! this has taken me all day to find!!!
Posted by Mark on 9 Nov 2007 at 9:05am
waaahhh! you're my saviour! i wanna cry with happiness!! thanx a lot!!
Posted by noahvearn on 11 Nov 2007 at 9:33pm
thanks man. all the people who wrote before me are right... many, many, THHHHHAAAAAAAAAANNNNNNNNKKKKKKKKSSSSSSSSSS!!!!
Posted by Manuel on 12 Nov 2007 at 4:24pm
Thank you so much, this saved my bacon big time.
Posted by Angus on 13 Nov 2007 at 7:25am
I love you as much as a heterosexual man can love another man.

Thanks!!
Posted by Noah on 14 Nov 2007 at 12:27pm
You are amazing!!!
Posted by Richard Freudenfeld on 19 Nov 2007 at 11:48am
You bailed me out on this one. Was beating my head against the wall so long that when it actually worked -- and so well -- I was amazed.
Posted by Calhoon on 21 Nov 2007 at 4:21pm
THANK YOU VERY VERY MUCH...

YOU SAVE MY LIFE ....

THANK YOU
Posted by Fawn (from Thailand) on 1 Dec 2007 at 12:39pm
excellent .....thanks for example.zip

thank a lot...!
Posted by samir panchal on 8 Dec 2007 at 6:06am
THANKS
Today is my deadline, and finally I find your blog with this GLORIOUS PROXY!!!! You just save my life.
THANKS
Posted by JuanM on 19 Dec 2007 at 6:59am
I cant thank you enough. The script works a treat and gets round the annoying problem of CS3 projectors not opening bat files properly.
Posted by David Jenkins on 1 Jan 2008 at 10:26am
Like everyone else on here...i would like to express my thanks for your help and solution...
Posted by Owen Hardy on 16 Jan 2008 at 10:57am
The 737th Training Support Squadron of the United States Air Force thanks you. All of the Visual Presentations used in the USAF Basic Training Acedimic classes are built and delivered via Flash Projector Files. These files are accessed through a Master Menu (also a Flash Projector file).

Most of the lessons incorporate video utlizing the media component, and when we moved to CS3, none of our videos would launch "if" the Lesson Presentation projector file was launched from the Main Menu projector file.

We do updates continually making this a serious problem, and Adobe essentially tried to tell us it was our fault.

So thank you very much.
Posted by Dave Terry on 16 Jan 2008 at 2:49pm
I just created my first CD-ROM based presentation with a Flash based EXE homepage that links to PDFs and Word docs. I was not aware of the getURL issue because the links worked fine on my PC. But when the client reviewed the project, they recieved all kinds of IE "Security Warning" messages because, as you know, the PDFs opened within IE and not the actual application and not to mention that the browser opened behind the projector file. I came across your wonderful "Proxy" solution in a Flashkit forum after 3 days of just trying to figure-out an ActionScript solution. Needless to say, that was hopeless.

So here I am, very relieved and happy. More importantly the client is happy and I can't thank you enough. THANK YOU, THANK YOU, THANK YOU!

Sincerely,

Will
Posted by Will Cruz on 25 Jan 2008 at 1:57pm
Thank you so much!
Posted by Valdemar De Matos on 1 Feb 2008 at 5:18am
Thanks! I am so glad this is here, becuase I scoured the web looking for a solution. I thought it was something I was doing wrong, nope just Adobe.
Posted by Jen Z on 5 Feb 2008 at 10:39pm
Thank you! This has saved my project from the grave!
Posted by Chris Burden on 6 Feb 2008 at 6:38pm
5 AM GMT +1, four hours of searching and finally i got it. THANK YOU. omg i can finally go sleep..
Posted by Jose Francisco De la Rua on 6 Feb 2008 at 11:06pm
THX A LOT !!! - Really Usefull
Posted by Tommy on 14 Feb 2008 at 4:06pm
It's so rare to find a Flash fix that works instantly, well done. Clear, concise instructions, and a perfect workaround.
Cheers!
Posted by Kim on 3 Mar 2008 at 5:39am
Thank you! This tutorial really very useful.
Posted by Amol on 4 Mar 2008 at 4:09am
dude! you're awesome!!
Posted by tina on 4 Mar 2008 at 12:15pm
thank you! your tutorial save me !
Posted by yuhei on 5 Mar 2008 at 6:49am
Many thanks! After hours of googling finally someone who explained, what the problem is (WAS!) and then also the solution!!! You're awesome, man!
Posted by chris on 6 Mar 2008 at 8:57am
It's working great ... thanks a lot!
Posted by Vince on 20 Mar 2008 at 10:52am
Excellent, thank’s from Costa Rica!!!
:)
Posted by Cristian on 27 Mar 2008 at 11:56am
AAAAHH!

I WONT GET FIRED!!

while(i<1000){
i++;
print("Thank you!!!");
}
Posted by MilanGM on 28 Mar 2008 at 10:22am
You saved my butt. Thanks a million!
Posted by Joe W on 2 Apr 2008 at 1:27am
thanks a lot! you solved my problem, thanks to people like you that dedicate a time to help when companies just leave us in the darkness. If wasn't for your article I could of been spending weeks trying to find out why it is not working, probably would end reinstalling version 4 or something, but your solution is much better, looks more professional!
Posted by abk on 3 Apr 2008 at 3:18pm
U saved my life :) Thank You !!!!!!!!!!!!!!!!!!!!!!!
Posted by DVDavy on 6 Apr 2008 at 8:39am
Eternal thanks, man! That's really awesome!!!
Posted by Michal Kuba on 13 Apr 2008 at 3:47pm
You have no idea of the struggle i had trying to open external video files with fscommand!!!!

You're a genius, thank's
Posted by Julian Perez on 14 Apr 2008 at 3:37pm
Excellent solution, you saved my live today!!
Posted by Maciek W on 22 Apr 2008 at 10:06am
thankyou soooo much
Posted by dave on 29 Apr 2008 at 8:15am
ThankS! You have saved my project!

:X
Posted by Stankiewicz on 1 May 2008 at 8:08am
txnx
Posted by mario on 2 May 2008 at 10:34am
AWESOME!!
Posted by TJ on 4 May 2008 at 1:08pm
Thanks for the updated tool. works like a champ.

You are KING!

Posted by BD72 on 9 May 2008 at 10:42am
thank you very much for your help!
Posted by pereda on 9 May 2008 at 7:39pm
Save my project too...tk
Posted by radu on 14 May 2008 at 3:55am
THANKS A LOT
Posted by ravindar on 15 May 2008 at 10:53am
Here in South Africa, in 2010, we will have a soccer world cup. I hereby offer you a free accommodation with electricity and water included.

Ndiyabulela kakhulu mhlekazi wam!!!!
Posted by Fezile Mlungu on 16 May 2008 at 9:07am
u da man
Posted by cup on 21 May 2008 at 2:59am
Just need to put another drop in the bucket. You really saved my project. (Deadline was tomorrow and I had NO idea that CS3/Flash9 was going to do this to me)
Posted by Fen on 25 May 2008 at 3:58pm
Another message of eternal gratitude!
Adobe should pay you every time someone comes across this problem and discovers your page!
Many many thanks.
Posted by grateful on 29 May 2008 at 6:15pm
Wow, it's amazing. You're really helping me out from this nightmare. Thank you so much!
Posted by madif on 30 May 2008 at 8:25pm
hi
I'm a beginner in flash but i'm a vb.net programmer and i always wanted to start a process from flash using fscommand, but it wasn't working.now that you've made this possible i thank you very much both for educating me and making me more interested in learning flash.

Posted by Mohsen on 1 Jun 2008 at 3:22am
this is really great...
Now I can make the CD structure as I want...
with the use of .bat .... the whole thing has become very flexible..

Thanks for the help...
Posted by Pratik on 2 Jun 2008 at 10:02am
This is really greaaaaaaaaat
ThanksThanksThanks...Thanks
Posted by Abdullah on 4 Jun 2008 at 2:27pm
The Answer To Life Universe And Everything...42...no...I mean...proxy.exe!
Posted by daniel on 5 Jun 2008 at 7:22am
I'll have to say, you solution works even better than expected. I was using another solution that opened PDFs just fine but when it came to opening video files, it just couldn't handle it (I think a Windows Media update had something to do with that). What's even better, the videos come up instantly versus the 3-5 second delay I was seeing. Thank you so much.
Posted by Dave Ramsey on 21 Jul 2008 at 9:51am
WOW

youre awesome dude!

btw the proxy.exe is not a harmful program right? :D :D :D
Posted by hadi on 22 Jul 2008 at 2:20am
If you got your copy of proxy from our site, it's safe and does only what the documentation says it does.
Posted by Tim on 22 Jul 2008 at 2:26am
Great Script. It saved my day.
Posted by Creationpool - Flash Agentur Berlin on 28 Jul 2008 at 7:40pm
AWEEEESOME man, you saved me today, i was fighting a deadline trying to run my c# application from flash, my application crashed on startup with ArgumentException not handled!

Thanks again. :)
Posted by eddiE on 30 Jul 2008 at 9:04am
Thaaaaaaaaaaaaaaaaaaaanx man alot

you give us a good help with this

:)
Posted by Ala on 31 Jul 2008 at 6:13am
Is the source code available for proxy.exe? We have a project where the client wants to see the command window while the batch file is running.
Posted by Brian on 31 Jul 2008 at 3:48pm
Normally I would have said "just call the BAT file directly", but the issue with CS3 not calling BAT files properly takes that option off the table. The source for proxy is not available, but I just emailed you a custom version of proxy that does what you need.
Posted by Tim on 31 Jul 2008 at 4:26pm
hatur nuhun
-thanx in sundanesse-
Posted by wdy on 7 Aug 2008 at 1:28pm
What if I only need to open a folder, not a file...?
Posted by edger on 12 Aug 2008 at 5:55pm
You can call explorer.exe in the BAT file to open the folder you want. For example

explorer.exe "c:\documents and settings"
Posted by tim on 12 Aug 2008 at 6:10pm
Thank you so much it works really well!
Posted by Stephan Stroh on 19 Aug 2008 at 8:09am
Hi, I'm not sure if this is even possible... here goes:

I have two .exe files that I want to open. One is the French version and one is the English version of the same player (.exe) file.

I would like to have two buttons in my main projector file, one to open the French .exe and one to open the English .exe.

Is there a way to do this?
Posted by Mary on 19 Aug 2008 at 12:21pm
Sure, you can use System.capabilities.language to find out what language the system is running and choose the EXE you want automatically OR you can just hard code the EXEC command for each button to call opene.exe and openf.exe (or whatever you want to call them)
Posted by Tim on 19 Aug 2008 at 12:56pm
This works for me to launch a pdf in Win2k/XP/Vista. However, it is *not* working for me to launch a .exe file in Vista. I am using Flash CS3.
Posted by Chris on 19 Aug 2008 at 4:42pm
What is the name of the EXE file you are trying to launch? Does the EXE have a "shield" on the icon?

Vista makes some assumptions about what you're trying to do based on the name of the EXE. If you have the "setup", "install" (or a few others) in the file name, Vista thinks those apps should have admin rights and when you try to launch them as a normal user they will fail. The shield on the icon is the clue that Vista thinks the application might need more rights

You could also be running into the problem using the start command in Vista that I describe in this post: Fixing the Windows Start Command in Vista.
Posted by Tim on 19 Aug 2008 at 5:42pm
Leave a Comment

Add a comment by filling out the form below. All comments will be reviewed before they appear.

name:

email:

website:

comment:


← Back
 

copyright © 2000-2008 Northcode Inc  ·  all rights reserved  ·  contact us  ·  report piracy  ·  privacy policy