include function - How to...

Convert your BATch files into EXEcutable format in one click.
fairlane76
Posts: 3
Joined: Thu Aug 11, 2005 11:07 am

Post by fairlane76 »

Hi,

How does one use the include facility?

I have made a backup solution in a .bat file which compresses a whole directory. So far I've had the compression utility on c:\7z\7z.exe
I have tried to call the included 7z.exe with the following commands without success:

7z.exe
CALL 7z.exe
CALL %systemdrive%\7z.exe
CALL %system%7z.exe

So, what is the path to a file included in the generated batch.exe?

Thanks.

FF
sixpack
Posts: 13
Joined: Wed Dec 08, 2004 9:16 am

Post by sixpack »

first of all your directory is c:\7z\7z.exe
so wy try to:
CALL 7z.exe
CALL %systemdrive%\7z.exe
CALL %system%7z.exe ???

it's %systemdrive%\7z\7z.exe

or

Code: Select all

@echo off
cd
7z.exe
if the batch file is in the same directory as the 7z.exe

note: to use 7z in a batch file use the
7za.exe
(standalone console version) not the 7z.exe

second
if you want to zip up a directory with 7z you MUST use swithes for 7z

Examples

Code: Select all

7z a -tzip archive.zip subdir\*

adds all files from directory subdir to archive archive.zip.

7z a -tzip Files.zip "Program files\*" -r

adds all files from directory Program to archive Files.zip
read more in the 7z help file

this is a backup batch file snipped that is use my self.
i use winrar instead of 7z but you get the idea (i hope)
if not exist "%USERPROFILE%\Application Data\Thunderbird" goto runa
echo ### Backup Maken van Mozilla thunderbird (Instellingen)...
if not exist "%drive%\Backup\Thunderbird" mkdir "%drive%\Backup\Thunderbird"
%backupcmd% "%USERPROFILE%\Application Data\Thunderbird" "%drive%\Backup\Thunderbird"
"%systemdrive%\Backup Diz\rar\WinRAR.exe" a -sfx -zThunderbird.diz -rr1%% -u -ed -ep1 -r -os -av -m4 "%drive%\Backup\Thunderbird" "%drive%\Backup\Thunderbird"
ECHO * Mozilla Thunderbird (Instellingen) >>%txt%
ECHO ---------------------------------- >>%txt%
dir "%USERPROFILE%\Application Data\Thunderbird" /s /b /-p /o:gn >>%txt%
ECHO. >>%txt%
ECHO.
ECHO.
ECHO.
:runa
if not exist "%programfiles%\Opera" goto run
echo ### Backup Maken van Opera Web Browser (Instellingen)...
if not exist "%drive%\Backup\Opera" mkdir "%drive%\Backup\Opera"
%backupcmd% "%programfiles%\Opera\Mail" "%drive%\Backup\Opera\Mail"
%backupcmd% "%programfiles%\Opera\profile" "%drive%\Backup\Opera\profile"
"%systemdrive%\Backup Diz\rar\WinRAR.exe" a -sfx -zOpera_mail.diz -rr1%% -u -ed -ep1 -r -os -av -m4 "%drive%\Backup\Opera\Mail" "%drive%\Backup\Opera\Mail"
"%systemdrive%\Backup Diz\rar\WinRAR.exe" a -sfx -zOpera_Profile.diz -rr1%% -u -ed -ep1 -r -os -av -m4 "%drive%\Backup\Opera\profile" "%drive%\Backup\Opera\profile"
if exist "%drive%\Backup\Opera\Mail.exe" ren "%drive%\Backup\Opera\Mail.exe" "Opera_Mail.exe"
if exist "%drive%\Backup\Opera\profile.exe" ren "%drive%\Backup\Opera\profile.exe" "Opera_Profile.exe"
ECHO * Opera Web Browser (Instellingen) >>%txt%
ECHO -------------------------------- >>%txt%
dir "%programfiles%\Opera\Mail" /s /b /-p /o:gn >>%txt%
dir "%programfiles%\Opera\profile" /s /b /-p /o:gn >>%txt%
ECHO. >>%txt%
ECHO.
ECHO.
ECHO.
:run
if not exist "%USERPROFILE%\Application Data\Mozilla" goto run0
echo ### Backup Maken van Mozilla Firefox (Instellingen)...
if not exist "%drive%\Backup\Mozilla" mkdir "%drive%\Backup\Mozilla"
%backupcmd% "%USERPROFILE%\Application Data\Mozilla" "%drive%\Backup\Mozilla"
"%systemdrive%\Backup Diz\rar\WinRAR.exe" a -sfx -zFirefox.diz -rr1%% -u -ed -ep1 -r -os -av -m4 "%drive%\Backup\Mozilla" "%drive%\Backup\Mozilla"
if exist "%drive%\Backup\Mozilla.exe" ren "%drive%\Backup\Mozilla.exe" "Mozilla_Firefox.exe"
ECHO * Mozilla Firefox (Instellingen) >>%txt%
ECHO ----------------------------- >>%txt%
dir "%USERPROFILE%\Application Data\Mozilla" /s /b /-p /o:gn >>%txt%
ECHO. >>%txt%
ECHO.
ECHO.
ECHO.
variables you can use
%CD% - Returns the current directory string.
%CMDCMDLINE% - Returns the exact command line used to start the current Cmd.exe.
%CMDEXTVERSION% - Returns the version number of the current Command Processor Extensions.
%COMSPEC% - Returns the exact path to the command shell executable.
%ERRORLEVEL% - Returns the error code of the most recently used command. A non zero value usually indicates an error.
%HOMEDRIVE% - Returns which local workstation drive letter is connected to the user's home directory.
%HOMEPATH% - Returns the full path of the user's home directory.
%HOMESHARE% - Returns the network path to the user's shared home directory.
%LOGONSEVER% - Returns the name of the domain controller that validated the current logon session.
%NUMBER_OF_PROCESSORS% - Specifies the number of processors installed on the computer.
%OS% - Returns the operating system name.
%PATH% - Specifies the search path for executable files.
%PATHEXT% - Returns a list of the file extensions that the operating system considers to be executable.
%PROCESSOR_ARCHITECTURE% - Returns the chip architecture of the processor. Values: x86, IA64.
%PROCESSOR_IDENTIFIER% - Returns a description of the processor.
%PROCESSOR_LEVEL% - Returns the model number of the processor installed on the computer.
%PROCESSOR_REVISION% - Returns the revision number of the processor.
%PROMPT% - Returns the command prompt settings for the current interpreter. Generated by Cmd.exe.
%RANDOM% - Returns a random decimal number between 0 and 32767. Generated by Cmd.exe.
%TEMP% - Returns the default temporary directories that are used by applications available to users who are currently logged on.
%TMP% - Some applications require TEMP and others require TMP.
%TIME% - Returns the current time.
%date% - returns the current date.
%USERDOMAIN% Returns the name of the domain that contains the user's account.
%WINDIR% Returns the location of the operating system directory.
%sysdir% - normally 'C:\WINDOWS\System32
%allusersprofile% - path to the all users profile directory
%userprofile% - path to the user profile directory
%commonprogramfiles% - path to common program files directory
%systemdrive% - normally 'C:\'
%windir% - normally 'C:\WINDOWS'
%programfiles% - normally 'C:\Programme Files
%userprofile% = C:\documents and settings\FRED (Fred is the current user logged on)
%AllUsersProfile% = C:\documents and settings\All Users
%USERNAME% = naam van de huidige gebruiker
%computername% = de computer naam
hope this helps you :)



Edited By sixpack on 1123803131
fairlane76
Posts: 3
Joined: Thu Aug 11, 2005 11:07 am

Post by fairlane76 »

Wow... Thanks for your very ellaborate answer. I especially find your listing of variables very useful.

About 7z. I am in fact using the 7za.exe and a whole lotta of parameters. But I guess I was too vague on my need.

Lets pretend that 7za.exe does not exist on my users computer. What I want is to include 7za.exe with the batch file, so that the user doesn't have to have the program anywhere on the computer. IE like a stand-alone application, an exe that includes both the batch file as well as the 7za.exe file.

The line I use to call 7za.exe is:
CALL 7za.exe a c:\temp\backup\data%date%.7z -r c:\data\*
But this doesn't work because the batch file doesn't recognize where the 7za.exe file is.
After this I simply open a network connection to my server and move the backup%date%.7z to the network share.

Any ideas on where the file is when its included in the batch.exe?

Thanks.

Kim

For anyone interested heres my backup procedure. When I get it to work I will include mail directories as well as bookmarks of both iexplorer and firefox.

@ECHO OFF
title Company Name - BACKUP @ %date%
REM ************************************************************
REM THIS BACKUP PROCEDURE HAS LAST BEEN REVISED 08AUG2005 BY Kim
REM ************************************************************
CLS
ECHO.
ECHO YOU HAVE STARTED THE BACKUP PROCEDURE
ECHO.
ECHO THIS PROCEDURE MIGHT TAKE A LITTLE WHILE
ECHO DEPENDING ON THE AMOUNT OF DATA YOU HAVE.
ECHO.
ECHO.
ECHO TO CANCEL THE OPERATION PRESS Ctrl+C
ECHO OR CLICK ON THE X IN THE CORNER OF THIS WINDOW
ECHO.
ECHO OR...
PAUSE
CLS
PING 192.168.0.2 ¦ FIND "Reply from " > NUL
IF ERRORLEVEL 1 GOTO check
IF ERRORLEVEL 0 GOTO offline

:check
NET USE V: \\server1\username password /USER:server1\username /PERSISTENT:NO > NUL
IF EXIST "v:\data%date%.7z" GOTO fileexists ELSE GOTO continue

:continue
CLS
ECHO.
ECHO BACKUP PROCEDURE IN PROGRESS...
ECHO.
ECHO PLEASE WAIT......
ECHO.

REM Compressing Files
echo.
echo Compressing your data
CALL 7za.exe a c:\temp\backup\data%date%.7z -r c:\data\* > NUL

REM Move The File
echo.
echo Copying data to network
move C:\temp\backup\*.7z v:\ > NUL

REM Close The Network Share
NET USE v: /delete > NUL

CLS
echo.
echo BACKUP PROCEDURE COMPLETE.
echo.
echo THANK YOU FOR YOUR PATIENCE!
echo.
echo.
echo *** REMEMBER TO SAVE YOUR FILES ATLEAST ONCE A WEEK ***
echo.
echo.
pause
exit

:offline
echo.
echo You are not connected to the network.
echo Please connect your computer to the network and try again.
echo.
echo If you are connected and still recieve this message, please
echo call your network administrator or send an email to admin@network.com
echo.
pause
exit

:fileexists
net use V: /delete > NUL
echo.
echo You have already performed backup today.
echo Have a nice day!
echo.
echo If this is an error, please call your network administrator
echo or send an email to admin@network.com
echo.
pause
exit
Oleg Tsheglov
Site Admin
Posts: 307
Joined: Fri Feb 13, 2004 5:55 pm

Post by Oleg Tsheglov »

You can download latest beta from https://www.abyssmedia.com/downloads/qbfc-beta.exe
and use %MYFILES% variable to get path to included files.
for example @call %MYFILES%/7za.exe
sixpack
Posts: 13
Joined: Wed Dec 08, 2004 9:16 am

Post by sixpack »

@fairlane76

try to use

Code: Select all

cd
7za.exe a c:\temp\backup\data%date%.7z -r c:\data\*


@Oleg Tsheglov
thanks for the beta



Edited By sixpack on 1123934196
fairlane76
Posts: 3
Joined: Thu Aug 11, 2005 11:07 am

Post by fairlane76 »

@Oleg

Thanks for the beta. It works like a charm.


@six

Thanks for your input. Didn't need to try your latest trick since Oleg gaves us a beta that works. Nevertheless, thank you for your help.

Best regards to both of you,
Kim
sixpack
Posts: 13
Joined: Wed Dec 08, 2004 9:16 am

Post by sixpack »

any time
thickfreakness
Posts: 14
Joined: Thu Apr 21, 2005 3:50 am

Post by thickfreakness »

Oleg Tsheglov wrote:You can download latest beta from https://www.abyssmedia.com/downloads/qbfc-beta.exe
and use %MYFILES% variable to get path to included files.
for example @call %MYFILES%/7za.exe
so included files now go to the "Application Data" folder?

anyway to make them go in the same folder as the compiled EXE?
Oleg Tsheglov
Site Admin
Posts: 307
Joined: Fri Feb 13, 2004 5:55 pm

Post by Oleg Tsheglov »

Yes, this guarantee that files will be decompressed (recommended by Microsoft).
When you decompress files to same folder as EXE:
1. You may not have permissions to write this folder under WinXP/2000/2003
2. EXE file runned from CD-ROM....

Ok. I can add this option to compiler: decompress to current folder/AppData folder/Temp folder....
thickfreakness
Posts: 14
Joined: Thu Apr 21, 2005 3:50 am

Post by thickfreakness »

Oleg Tsheglov wrote:Yes, this guarantee that files will be decompressed (recommended by Microsoft).
When you decompress files to same folder as EXE:
1. You may not have permissions to write this folder under WinXP/2000/2003
2. EXE file runned from CD-ROM....

Ok. I can add this option to compiler: decompress to current folder/AppData folder/Temp folder....
that would be great
daver
Posts: 1
Joined: Thu Sep 08, 2005 11:09 am

Post by daver »

Oleg Tsheglov wrote:Ok. I can add this option to compiler: decompress to current folder/AppData folder/Temp folder....
Ok, I'm confused.

I just tried the include function. I used %MYFILES% in the call path to all included files. But the files were extracted to the folder the application was run from.

I changed the call paths back to the original paths, compiled and ran my test app again. This time it still decompressed the included files to current directory, but they were now all 0KB.

Dave



Edited By daver on 1126178578
Oleg Tsheglov
Site Admin
Posts: 307
Joined: Fri Feb 13, 2004 5:55 pm

Post by Oleg Tsheglov »

Daver,
%MYFILES% supported only in latest beta-version https://www.abyssmedia.com/downloads/qbfc-beta.exe