TechKnow

Author Topic: [BAT-Windows Shell Extension] ZARCH - Easy archiver!  (Read 1040 times)

0 Members and 1 Guest are viewing this topic.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9936
  • Karma: +2284/-111
[BAT-Windows Shell Extension] ZARCH - Easy archiver!
« on: December 11, 2015, 02:04:42 PM »
ZARCH

ZARCH is the ZDiR Archiver component, this is a standalone version of it. Basically, this is a Shell Extension for Windows, easy to use and uses a freeware archive util (7za.exe).

Adds 6 features to Windows Explorer:

For files:
* Add to .7z
* Add to .zip
* Extract here
* Extract to dir

For directories:
* Add to 7z archive
* Add to zip archive

Capable of extracting:
*.7z
*.zip
*.gz
*.tar
*.tar.gz
*.bzip2
*.tgz

Installation:
1. Get yourself 7za.exe:
http://www.7-zip.org/download.html (command line version) or direct: http://www.7-zip.org/a/7za920.zip

2. Copy and paste the ZARCH.BAT code below to a new .BAT file

3. Place 7za.exe in the same directory and start your new .BAT file called ZARCH.BAT

4. Type "i" to install or "u" to uninstall


Code: (ZARCH.BAT) [Select]
:ZARCH
@echo off
set debug=0
color 0a
title Z_Archiver
for %%* in (%2) do set DIRNAMEX=%%~dp*
for %%* in (%2) do set FILENAMEX=%%~nx*
for %%* in (.) do set DIRNAME=%%~nx*
for %%F in (%2) do set FILENAME=%%~nF
for %%F in (%2) do set FILEEXT=%%~xF
if %debug% == 1 echo Dirname=%DIRNAME%
if %debug% == 1 echo Dirnamex=%DIRNAMEX%
if %debug% == 1 echo Filname=%FILENAME%
if %debug% == 1 echo FilnameX=%FILENAMEX%
if %debug% == 1 echo FileExt=%FILEEXT%
if debug == 1 pause
CD /D %DIRNAMEX%
if /i "%1"=="7z" goto :MAKEDIR7Z
if /i "%1"=="7zf" goto :MAKEFILE7Z
if /i "%1"=="zip" goto :MAKEDIRZIP
if /i "%1"=="zipf" goto :MAKEFILEZIP
if /i "%1"=="e" goto :ZARCHEXTRACTHERE
if /i "%1"=="ed" goto :ZARCHEXTRACTTODIR
if /i "%1"=="extractdir" goto :ZARCHEXTRACTTODIR
if /i "%1"=="extract" goto :ZARCHEXTRACT
if /i "%1"=="i" goto :ZARCHINTEGRATE
if /i "%1"=="u" goto :ZARCHUNINST
if "%1"=="" cls && echo No directory path input received. && GOTO :ZARCHINTEGRATEX

:ZARCHEXTRACTHERE
if "%FILEEXT%"==".7z" goto :ZARCHEXTRACTHERESTART
if "%FILEEXT%"==".gz" goto :ZARCHEXTRACTHERESTART
if "%FILEEXT%"==".tar.gz" goto :ZARCHEXTRACTHERESTART
if "%FILEEXT%"==".tgz" goto :ZARCHEXTRACTHERESTART
if "%FILEEXT%"==".zip" goto :ZARCHEXTRACTHERESTART
if "%FILEEXT%"==".bzip2" goto :ZARCHEXTRACTHERESTART
if "%FILEEXT%"==".gzip" goto :ZARCHEXTRACTHERESTART
if "%FILEEXT%"==".tar" goto :ZARCHEXTRACTHERESTART
color 0c
echo %FILEEXT% is not supported.
pause
goto :ZARCHEOF
:ZARCHEXTRACTHERESTART
echo ZARCH
echo input: %2
echo output: %DIRNAMEX%
7za l %2
echo.&&echo Press any key to extract file^(s^) to %CD%.&&PAUSE >NUL
7za x -r -o"%DIRNAMEX%" %2
echo.
pause
goto :EOF

:ZARCHEXTRACTTODIR
if "%FILEEXT%"==".7z" goto :ZARCHEXTRACTSTART
if "%FILEEXT%"==".gz" goto :ZARCHEXTRACTSTART
if "%FILEEXT%"==".tar.gz" goto :ZARCHEXTRACTSTART
if "%FILEEXT%"==".tgz" goto :ZARCHEXTRACTSTART
if "%FILEEXT%"==".zip" goto :ZARCHEXTRACTSTART
if "%FILEEXT%"==".bzip2" goto :ZARCHEXTRACTSTART
if "%FILEEXT%"==".gzip" goto :ZARCHEXTRACTSTART
if "%FILEEXT%"==".tar" goto :ZARCHEXTRACTSTART
color 0c
echo %FILEEXT% is not supported.
pause
goto :ZARCHEOF
:ZARCHEXTRACTSTART
:ZARCHEXTRACT
echo ZARCH
echo input: %2
echo output: %DIRNAMEX%%FILENAME%
7za l %2
echo.&&echo Press any key to extract file^(s^) to %DIRNAMEX%%FILENAME%.&&PAUSE >NUL
7za x -r -o"%DIRNAMEX%%FILENAME%" %2
echo.
pause
goto :EOF

:MAKEDIR7Z
echo.&&echo Adding files to "%DIRNAME%.7z" ...
7za.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r -mmt "%DIRNAME%.7z" *.*
goto :ZARCHEOF

:MAKEDIRZIP
echo.&&echo Adding files to "%DIRNAME%.zip" ...
7za.exe a -tzip -r -mmt "%DIRNAME%.zip" *.*
goto :ZARCHEOF

:MAKEFILE7Z
echo.&&echo Adding file to "%FILENAME.7z" ...
7za.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r -mmt "%FILENAME%.7z" %2
goto :ZARCHEOF

:MAKEFILEZIP
echo.&&echo Adding file to "%FILENAME.zip" ...
7za.exe a -tzip -r -mmt "%FILENAME%.zip" %2
goto :ZARCHEOF

:ZARCHINTEGRATEX
set choice=
echo.
echo Would you like to install and integrate or uninstall ZARCH?
set /p choice=Enter i^/u^/q:
if "%CHOICE%"=="" goto :ZARCHINTEGRATEX
if "%CHOICE%"=="i" goto :ZARCHINTEGRATE
if "%CHOICE%"=="u" goto :ZARCHUNINST
if "%CHOICE%"=="q" goto :ZARCHEOF

:ZARCHINTEGRATE
copy ZARCH.BAT %windir%\system32
if %errorlevel%==1 color 0c&&echo.&&echo ERROR: UNABLE TO COPY ZARCH to %windir%\system32!&&echo.&&PAUSE&&EXIT
copy 7za.exe %windir%\system32
if %errorlevel%==1 color 0c&&echo.&&echo ERROR: UNABLE TO COPY 7za to %windir%\system32!&&echo.&&PAUSE&&EXIT

if not exist %windir%\system32\7za.exe color 0c && echo ERROR: Copy to system32 failed, run this as administrator.&&PAUSE&&EXIT

REG ADD "HKCR\Directory\shell\Add to 7z archive\Command" /f /ve /t REG_SZ /d "cmd.exe /s /k pushd "%%V" & ZARCH 7z"
REG ADD "HKCR\Directory\shell\Add to zip archive\Command" /f /ve /t REG_SZ /d "cmd.exe /s /k pushd "%%V" & ZARCH zip"

REG ADD HKCR\.7z /f /ve /t REG_SZ /d "Uberizer.7z"
REG ADD HKCR\Uberizer.7z\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.7z\OpenWithProgids /f /v "Uberizer.7z" /t REG_NONE

REG ADD HKCR\.7z /f /ve /t REG_SZ /d "Uberizer.zip"
REG ADD HKCR\Uberizer.zip\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.zip\OpenWithProgids /f /v "Uberizer.zip" /t REG_NONE

REG ADD HKCR\.gz /f /ve /t REG_SZ /d "Uberizer.gz"
REG ADD HKCR\Uberizer.gz\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.gz\OpenWithProgids /f /v "Uberizer.gz" /t REG_NONE

REG ADD HKCR\.tgz /f /ve /t REG_SZ /d "Uberizer.tgz"
REG ADD HKCR\Uberizer.tgz\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tgz\OpenWithProgids /f /v "Uberizer.tgz" /t REG_NONE

REG ADD HKCR\.gzip /f /ve /t REG_SZ /d "Uberizer.gzip"
REG ADD HKCR\Uberizer.gzip\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.gzip\OpenWithProgids /f /v "Uberizer.gzip" /t REG_NONE

REG ADD HKCR\.bzip2 /f /ve /t REG_SZ /d "Uberizer.bzip2"
REG ADD HKCR\Uberizer.bzip2\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bzip2\OpenWithProgids /f /v "Uberizer.bzip2" /t REG_NONE

REG ADD HKCR\.tar /f /ve /t REG_SZ /d "Uberizer.tar"
REG ADD HKCR\Uberizer.tar\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tar\OpenWithProgids /f /v "Uberizer.tar" /t REG_NONE

REG ADD HKCR\.tar.gz /f /ve /t REG_SZ /d "Uberizer.tar.gz"
REG ADD HKCR\Uberizer.tar.gz\shell\open\command /f /ve /t REG_SZ /d "ZARCH EXTRACT ""%%1"""
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tar.gz\OpenWithProgids /f /v "Uberizer.tar.gz" /t REG_NONE

REG ADD "HKCR\*\shell\Add to .7z\command" /f /ve /t REG_SZ /d "ZARCH 7zf \"%%1\""
REG ADD "HKCR\*\shell\Add to .zip\command" /f /ve /t REG_SZ /d "ZARCH zipf \"%%1\""
REG ADD "HKCR\*\shell\Extract here\command" /f /ve /t REG_SZ /d "ZARCH e \"%%1\""
REG ADD "HKCR\*\shell\Extract to dir\command" /f /ve /t REG_SZ /d "ZARCH ed \"%%1\""

GOTO :ZARCHEOF

:ZARCHUNINST

REG DELETE "HKCR\*\shell\Add to .7z" /F
REG DELETE "HKCR\*\shell\Add to .zip" /F
REG DELETE "HKCR\*\shell\Extract here" /F
REG DELETE "HKCR\*\shell\Extract to dir" /F

REG DELETE "HKCR\Directory\shell\Add to 7z archive" /F
REG DELETE "HKCR\Directory\shell\Add to zip archive" /F

REG DELETE "HKCR\Uberizer.7z" /F
REG DELETE "HKCR\Uberizer.zip" /F
REG DELETE "HKCR\Uberizer.gz" /F
REG DELETE "HKCR\Uberizer.tgz" /F
REG DELETE "HKCR\Uberizer.gzip" /F
REG DELETE "HKCR\Uberizer.bzip2" /F
REG DELETE "HKCR\Uberizer.tar.gz" /F
REG DELETE "HKCR\Uberizer.tar" /F

REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.7z\OpenWithProgids /f /v "Uberizer.7z"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.zip\OpenWithProgids /f /v "Uberizer.zip"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.gz\OpenWithProgids /f /v "Uberizer.gz"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tgz\OpenWithProgids /f /v "Uberizer.tgz"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.gzip\OpenWithProgids /f /v "Uberizer.gzip"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bzip2\OpenWithProgids /f /v "Uberizer.bzip2"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tar.gz\OpenWithProgids /f /v "Uberizer.tar.gz"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tar\OpenWithProgids /f /v "Uberizer.tar"

echo.
echo ZARCH Uninstallation completed.
echo.
pause

:ZARCHEOF

exit

Enjoy this handy shell extension!

HcH

Offline huckleberrypie

  • Sr. Member
  • ****
  • Posts: 498
  • Karma: +241/-1
  • Unterganger.
  • Tablet / Size / Model: KingCom Joypad Q71 (Allwinner A31s/7")
Re: [BAT-Windows Shell Extension] ZARCH - Easy archiver!
« Reply #1 on: December 12, 2015, 12:21:50 PM »
Mostly because there are some who find doing things in batch a bit more leet lol. Not sure if I can find some use for this, but let's see.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9936
  • Karma: +2284/-111
Re: [BAT-Windows Shell Extension] ZARCH - Easy archiver!
« Reply #2 on: December 12, 2015, 02:30:10 PM »
Mostly because there are some who find doing things in batch a bit more leet lol. Not sure if I can find some use for this, but let's see.
You're spot on! Just because it can :) And since 7zip is nice and all but basically I just use a few options to create archives and extract some.

Offline cyberwind

  • Site Donor
  • Newbie
  • *
  • Posts: 25
  • Karma: +12/-0
  • Uber-Noobie
  • Tablet / Size / Model: homemade/7/galaxy5
Re: [BAT-Windows Shell Extension] ZARCH - Easy archiver!
« Reply #3 on: December 15, 2015, 04:14:45 AM »
Thanks. For the scripts and the snow.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9936
  • Karma: +2284/-111
Re: [BAT-Windows Shell Extension] ZARCH - Easy archiver!
« Reply #4 on: December 16, 2015, 09:17:44 AM »
Thanks. For the scripts and the snow.
You're more than welcome! I love these kind of scripts, useful, simple, just pure fun.

When I had the idea for a simple archiver script for Windows I immediately started and had a lot of fun making it.

This example also shows very well how one can integrate functionality to Windows :)  :android-tongue: :cool-android: