Solved

Simple password protected zip file creation on windows desktop

Posted on 2013-10-23
10
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85

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
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 
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 85

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
 
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 85

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 85

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
In this article we have discussed the manual scenarios to recover data from Windows 10 through some backup and recovery tools which are offered by it.
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 …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

717 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