我必须压缩文件夹中的所有文件并使其受密码保护。
我用Google搜索并找到了一个使用Windows内置功能的解决方案。代码如下:
folder1 = "F:\WLMS_TEAM\TOUHID\Script"
zipfile = "F:\WLMS_TEAM\TOUHID\MyTmp.zip"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.OpenTextFile(zipfile, 8, True).Write "PK" & Chr(5) & Chr(6) _
& String(18, Chr(0))
Set ShellApp = CreateObject("Shell.Application")
Set zip = ShellApp.NameSpace(zipfile)
zip.CopyHere folder1
WScript.Sleep 2000
我可以设置密码保护吗?
或者,如果您可以帮助使用其他代码来使用WinZip(而不是任何其他工具)来实现相同的目标。
或者可以使用单独的代码来密码保护预先生成的zip文件。
答案 0 :(得分:1)
您可以在命令行上运行WinZip,如下所示:
2015-06-18 09:04:04.377,54954.418
2015-06-18 09:04:48.863,54965.438
2015-06-18 09:05:29.080,49.813
2015-06-18 09:06:04.697,45.187
2015-06-18 09:06:40.719,45.238
2015-06-18 09:07:09.693,38.768
2015-06-18 09:07:35.856,36.315
2015-06-18 09:08:06.961,39.789
2015-06-18 09:08:33.241,36.147
2015-06-18 09:09:02.801,38.473
2015-06-18 09:09:36.559,44.839
2015-06-18 09:10:13.222,46.165
2015-06-18 09:10:47.867,44.115
2015-06-18 09:11:25.807,46.985
2015-06-18 09:12:00.512,43.607
2015-06-18 09:12:37.513,46.552
2015-06-18 09:13:10.408,41.507
2015-06-18 10:13:44.107,43.269
2015-06-18 10:14:20.501,47.001
2015-06-18 10:15:00.061,52.589
2015-06-18 11:15:33.501,42.148
2015-06-18 11:16:07.558,43.919
2015-06-18 11:16:41.851,43.369
2015-06-18 11:17:15.159,43.336
2015-06-18 11:17:47.217,40.965
2015-06-18 11:18:23.135,44.12
2015-06-18 11:18:55.547,41.432
2015-06-18 12:19:32.362,45.522
2015-06-18 12:20:04.456,42.339
2015-06-18 12:20:36.559,40.555
2015-06-18 12:21:08.409,40.534
2015-06-18 12:21:38.170,38.706
2015-06-18 12:22:09.108,38.653
2015-06-18 12:22:34.420,33.234
2015-06-18 12:23:01.319,35.665
包装在VBScript中:
winzip32.exe -a -s"Password" "C:\path\to\your.zip" *.*
我认为Set sh = CreateObject("WScript.Shell")
sh.Run "winzip32.exe -a -s""Password"" ""C:\path\to\your.zip"" *.*", 0, True
对象不允许创建受密码保护的zip文件。
答案 1 :(得分:0)
经过长时间的搜索,反复试验,我得到了如下工作: 我希望出来寻找类似问题的人可能会发现它很有用。
strWinZipDir = "C:\Program Files\WinZip\WINZIP64.exe"
strZipFileToCreate = LocalPath & "FileName.zip"
strFilesToZip = LocalPath & "*.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strWinZip = objFSO.GetFile(strWinZipDir).ShortPath
strCommand = strWinzip & " -min -a -s""Password"" -r """ & strZipFileToCreate & """ " & strFilesToZip
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strCommand)
Do While objExec.Status = 0
Wscript.Sleep(200)
Loop
Set objShell = Nothing
Set objExec = Nothing
Set objFSO = Nothing