Solved

[PHP and Batch] Save files as a self-extracting executable

Posted on 2008-06-10
4
380 Views
Last Modified: 2013-12-13
Hi collegeues,

In PHP i'm creating a bunch of batch files (based on what settings a user gives) that need to be downloaded and executed on the users computer.
I trought it would be nice if the user only has to download an executable file that is a self extracting archive and contains a bunch of batch files and other tools.

The self extracting file has to:
 - Extract to a given path without asking the user for it, for example c:\insttemp
 - Run a batch file after extraction, for example: c:\insttemp\start1.cmd
 - Have no user interaction (unattended, so not even a confirmation) so a user is'nt able to do it wrong, just download and run.

I am able to create such a file using 7z (7zip command line utility) and an executable header i can copy in front of the file: (copy /b header.bin + settings.cfg + archive.7z executable.exe) but i dont think this is a very nice and stable solution.
This way i have to:
 - Safe all the files from php in a temp folder on the server
 - exec("7z blah blah") to archive them
 - exec("copy /b blah blah") to make it self extracting
 - Offer the file for downloading

I know i can save files to a .zip archive in php directly, wich is already way more stable, but i cant convert a zip file to a 7z file without unpacking it, so exact the same problem, even more steps.
I know i can make a self extracting file from a zip file using command line tools, but i cant give them the exact extracting path and a file to run afterwards _without_ user interaction (well i did'nt find one yet and looked up over 50 different tools).

Anyone has an idea to make this nice?
0
Comment
Question by:JapyDooge
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
eagle00789 earned 500 total points
ID: 21754868
the only viable solution i can give you is below in the code field. Make this into a batchfile you put on the server. that batchfile does everything in one go for you
When you save the contents below to a file, you can call it with "compressor.bat compressed c:\compressing"
What the code does is exactly what you code also does, but this file is the only one you need to call and does it all for you.
compressor <filename> <dir with files to compress>
also, make sure that the file config.txt is also in the dir with files to compress.
@echo off
echo Please wait while zipping the files...
7z a -t7z %2\%1.7z %2\*.* -x!config.txt
echo Please wait while creating the selfextractor
copy /b 7zS.sfx + %2\config.txt + %2\%1.7z %2\%1.exe

Open in new window

0
 
LVL 6

Author Comment

by:JapyDooge
ID: 21757701
Hmm thanks, that's not a bad idea. Becouse it's one file theres less changes it fails becouse something was'nt finished yet...
I'll hold this question open for a few more hours to see if someone else maybe has a great idea, otherwise i'll do it that way (well i would slightly change it but i got the idea).
0
 
LVL 6

Author Comment

by:JapyDooge
ID: 21759813
And so be it :)
0
 
LVL 6

Author Closing Comment

by:JapyDooge
ID: 31465750
Not exactly were i was looking for, but it does the job after all ;-) Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question