在Windows 10中从批处理运行VBS脚本时解压缩文件错误 [英] Unzip file error when running VBS script from a batch in Windows 10
问题描述
运行VBS时解压缩代码批处理在Win 10,我得到以下错误。这是什么可能是一个原因,因为据报道他人之前工作?更改目标目录或明确设置它们不会影响错误。
When running the VBS unzip code batch in Win 10, I'm getting the error below. What can be a reason for this, given it was reported working before by others? Changing target directories or explicitly setting them doesn't affect the error.
@echo off
setlocal enabledelayedexpansion
cd /d %~dp0
set vbs="%temp%\_.vbs"
call :UnZipFile "E:\Temp\" "%USERPROFILE%\Downloads\archive.zip\"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
::error
VBScript runtime error: Object required: 'objShell.NameSpace(...)'
编辑:更改.zip文件位置,现在脚本工作。错误原因是用户下载文件夹移动到不同的卷比较默认%USERPROFILE%\Downloads。该脚本似乎有问题与系统文件夹符号链接正常工作。
changed .zip file location, now the script works. The error reason was user Download folder moved to a different volume compare to default %USERPROFILE%\Downloads. The script seems to have issues working properly with system folder symlinks.
推荐答案
此批处理混合是基于VBS脚本面条。它相当好地执行文件解压缩工作,同时具有不需要与原始批次相比较的独立VBS文件的优点,或完全放弃批量脚本以利于VBS。
This batch hybrid is based on the VBS script suggested here by Noodles. It does file unzipping job fairly well, while having the advantage of not requiring a standalone VBS file compare to the original batch, or abandoning the batch script completely in favor of VBS. It does require a target directory for unzipped files to exist.
<!-- : Begin batch script
@echo off
set "dir=%temp%\Unzip" & set "file=%userprofile%\Downloads\archive.zip"
cscript //nologo "%~f0?.wsf" "%file%" "%dir%"
exit /b
----- Begin wsf script --->
<job><script language="VBScript">
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set DestFldr=objShell.NameSpace(Ag(1))
Set SrcFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
</script></job>
VBS方法似乎在符号链接问题或找到当前文件夹路径,从默认位置下载文件夹。在这种情况下,在cscript参数中使用绝对路径,而不是环境变量。
The VBS method seems to have issues with symlinks or locating a current folder path, if you moved the user Downloads folder from its default location. Use absolute paths in cscript arguments in this case instead of environmental variables.
这篇关于在Windows 10中从批处理运行VBS脚本时解压缩文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!