Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-10
4
Medium Priority
?
386 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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …
Suggested Courses

963 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