Solved

Simple password protected zip file creation on windows desktop

Posted on 2013-10-23
10
387 Views
Last Modified: 2013-10-23
I'd like to create a bat file or smiler that you can drag and drop a file onto and the bat file zips it up files dropped on with a predefined password.

It would be great if I could use 7zip or similar and not have to buy a utility.

Many thanks in advance
0
Comment
Question by:Glyn Merritt
  • 5
  • 4
10 Comments
 
LVL 16

Expert Comment

by:joinaunion
ID: 39595319
0
 
LVL 1

Author Comment

by:Glyn Merritt
ID: 39595343
This is exactly what I want to do but with all the manual steps cut out.

The idea is that instead of having to right mouse click select add to archive change the archive to zip format and type in a password etc... they just drop the file they wish to zip and password protect onto an icon on the desktop and then it creates a zip file that is protected with a predefined password.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 39595387
Try this for starters. It creates the archive based on name and the location of the original file, with the extension .zip.
Do you need to process several files dropped at the same time as well (and if so, do you want individual archives for each file, or one archive file)?
What if a folder is dropped on the script?
@echo off
setlocal
set "Password=Top & Secret"
set SevenZip=%ProgramFiles%\7-Zip\7z.exe
if "%~1"=="" goto :eof
"%SevenZip%" a -o"%~dp1" -p"%Password%" -tzip "%~n1.zip" "%~1"
if errorlevel 1 (
	color 4f
	pause
)

Open in new window

0
 
LVL 1

Author Comment

by:Glyn Merritt
ID: 39595413
That looks great.

It would be superb if it could handle both single and multiple files creating just the one archive with all the dropped files contained.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 39595444
How do you want the archive name generated in case of several files (note that the order in which they're passed to the script by Explorer is random)?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:Glyn Merritt
ID: 39595454
I guess it would make sense to use the short date and time for the file name if possible.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 39595475
Let me rephrase: if only one file is dropped, generating the archive name is obvious.
But if several files are selected in Explorer and then dropped on the batch file, the order in which they appear as arguments in the batch file is random. in this case, do you have any preference which of the files (alphabetically first one?) should be the basis for the new file name, or do you rather want a generic hard-coded name like "MultiFile-Archive.zip"?
0
 
LVL 1

Author Comment

by:Glyn Merritt
ID: 39595482
Hey oBdA

I was thinking the name of the archive file could be based on the current time and date at the time the archive was created if that is possible?

Many thanks,
G
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39595522
In case of a single file, it now still uses the original name as base, for multiple files, it uses a hard-coded prefix and then a time stamp (generated using WMI, so not depending on a certain date format like mm/dd/yyyy):
@echo off
setlocal enabledelayedexpansion
set "Password=Top & Secret"
set BaseNameMulti=Archive-
set SevenZip=%ProgramFiles%\7-Zip\7z.exe
if "%~1"=="" goto :eof
if "%~2"=="" (
	set ArchiveName=%~n1.zip
	goto SkipGetTime
)
echo Getting time ...
for /f "tokens=1-9" %%a in ('wmic Path Win32_LocalTime Get Day^,DayOfWeek^,Hour^,Minute^,Month^,Quarter^,Second^,WeekInMonth^,Year ^| find /v ""') do (
  set /a Line += 1
  if "!Line!"=="1" (set VarA=%%a&set VarB=%%b&set VarC=%%c&set VarD=%%d&set VarE=%%e&set VarF=%%f&set VarG=%%g&set VarH=%%h&set VarI=%%i)
  if "!Line!"=="2" (set !VarA!=%%a&set !VarB!=%%b&set !VarC!=%%c&set !VarD!=%%d&set !VarE!=%%e&set !VarF!=%%f&set !VarG!=%%g&set !VarH!=%%h&set !VarI!=%%i)
)
for %%a in (Month Day Hour Minute Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
set TimeStamp=%Year%%Month%%Day%_%Hour%%Minute%%Second%
set ArchiveName=%BaseNameMulti%%TimeStamp%.zip
:SkipGetTime

"%SevenZip%" a -o"%~dp1" -p"%Password%" -tzip "%ArchiveName%" %*
if errorlevel 1 (
	color 4f
	pause
	goto :eof
)

Open in new window

0
 
LVL 1

Author Closing Comment

by:Glyn Merritt
ID: 39595535
This is a stunning solution many thanks!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

759 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

24 Experts available now in Live!

Get 1:1 Help Now