Solved

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

Posted on 2008-06-10
4
376 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now