Solved

Simple password protected zip file creation on windows desktop

Posted on 2013-10-23
10
392 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 84

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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 84

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 84

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 84

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

733 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