Proposal: prefer bundled tar.exe over Shell32 CopyHere for driver zip extraction (with Shell32 fallback) #200
Replies: 1 comment
|
I will add some supplementary comments to Copilot’s explanation. 🎯 Summary: tar.exe is the modern best practice for ZIP extraction in VBAYour conclusion is correct: For Windows 10/11 environments, tar.exe is the safest, fastest, and most reliable method for ZIP extraction from VBA. Below is the full English explanation. 🧩 Why traditional VBA ZIP extraction is problematicVBA’s
In short, it is a legacy mechanism and not suitable for modern automation. 💣 PowerShell Expand-Archive: powerful but dangerous in real environmentsA popular modern workaround is: vba This works well technically:
However, it has a fatal flaw: ❗ Antivirus false positivesLaunching PowerShell invisibly from Excel is exactly what ransomware does. As a result:
This is not a “false positive” — it is a correct detection of suspicious behavior. Therefore, PowerShell-based extraction is not viable in real-world corporate environments. 🏆 The modern “true best solution”: tar.exeSince Windows 10 (Build 17063, 2018), コード Despite the name, this is actually bsdtar, a world‑class archiving tool that supports ZIP natively. Why tar.exe is the best choice
🧪 The “ideal” VBA ZIP extraction functionvba
Example callvba ✨ Why this method is unbeatable✔ 1. Native to WindowsWorks on all Windows 10/11 systems with zero preparation. ✔ 2. Perfect synchronous behavior
✔ 3. Antivirus-friendlytar.exe is a trusted OS binary, not a scripting engine. ✔ 4. Fast and robustbsdtar handles:
Better than PowerShell’s 🧩 Weak points (for completeness)To be fair, tar.exe has a few limitations:
But for modern Windows environments, these issues are negligible. 🏁 Final evaluation (2026)
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
DownloadAndInstallDrivercurrently extracts the driver executable from thedownloaded zip using
Shell32.Folder.CopyHere. This works, butCopyHerecancomplete asynchronously, so the code that runs immediately after it relies on the
extraction having already finished. I'd like to propose using the Windows-bundled
tar.exe(bsdtar) as the primary extractor, while keeping the existingCopyHerepath as a fallback so behavior is unchanged on systems withouttar.exe.Motivation
tar.exeinvoked viaWshShell.Run(cmd, 0, True)is fullysynchronous, so the subsequent
FileSystemObject.CopyFilecan no longer runbefore extraction finishes. The current code calls
CopyHereand thenimmediately copies the extracted file, relying on
CopyHerehaving completed.tar.exeships inSystem32on Windows 10 1803+ andWindows 11.
CreateObject. It reuses theIWshRuntimeLibraryreference the module already imports.
Proposed change
In
DownloadAndInstallDriver, the singleCopyHereline:is replaced by a call to a small helper:
The helper (
extractDriverFromZip, plus atarIsAvailablecheck) preferstar.exeand falls back toShell32whentar.exeis absent. It derives--strip-componentsfrom the member path, so the exe lands flat for both thenested Chrome 115+ layout (
chromedriver-win64/chromedriver.exe) and the flatEdge/Firefox layouts.
Dim shll As New Shell32.Shellis removed fromDownloadAndInstallDriverand moves into the fallback branch; no referencechanges are needed (
Shell32is still used byClass_InitializeandGetDownloadsFolderPath).I'm attaching the BiDi-extended build, which contains the updated
WebDriverManager(this build also removes the WMI dependency).SeleniumVBA7.3_BiDi.xlsm
Testing
Tested on Windows [version11] with Chrome, Edge, and Firefox: the driver
installs correctly via the
tar.exepath, and the fallback branch reproducesthe original
CopyHerebehavior.AV false positives
I scanned the BiDi-extended test build on VirusTotal and it came back 0/64.
Spawning
tar.exe— a signed archiver inSystem32, not a script engine —appears to carry a very low AV false-positive risk.
Backward compatibility
On systems without
tar.exe, the fallback runs the originalCopyHerelogic,so there is no behavior change there.
Reference
A nice independent write-up comparing VBA unzip approaches (Shell.Application,
PowerShell, 7-Zip,
tar.exe, pure-VBA, and a CDP trick), concluding thattar.exeis the modern best answer on Windows 10/11. It's in Japanese, but thecode samples and the comparison table are easy to follow:
https://qiita.com/Eschamali/items/c7c063fca19f303cab90
Disclosure: the code was drafted with AI assistance and reviewed and verified
by me.
All reactions