在Win 10中运行VBS unzip code批处理时,我将得到下面的错误。鉴于其他人以前曾报告说,这是什么原因?更改目标目录或显式设置它们不会影响错误。
@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%\下载不同的卷。脚本似乎存在与系统文件夹符号链接正常工作的问题。
发布于 2016-07-27 12:03:15
这批混合是基于VBS脚本,这里建议面条。它很好地完成了文件解压缩工作,同时与原始批处理相比,它不需要一个独立的VBS文件,或者完全放弃批处理脚本以支持VBS。它确实需要一个目标目录才能存在解压缩文件。
<!-- : 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参数中使用绝对路径,而不是使用环境变量。
发布于 2016-07-26 22:26:32
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
Msgbox "Finished"这个代码解压缩。
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\David Candy>"C:\Users\David Candy\Desktop\David\Documents\Assorted\Scripts\UnZip.vbs" "C:\Users\David Candy\Desktop\42 - ProcessExplorer.zip" "C:\Users\David Candy\Desktop\New Folder (3)"这是一个调试版本。用CScript运行它。
On Error Resume Next
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
wscript.echo Ag(0) & " Is Drive " & fso.DriveExists(Ag(0)) & " Is Folder " & fso.FolderExists(Ag(0)) & " Is File " & fso.FileExists(Ag(0))
wscript.echo Ag(1) & " Is Drive " & fso.DriveExists(Ag(1)) & " Is Folder " & fso.FolderExists(Ag(1)) & " Is File " & fso.FileExists(Ag(1))
wscript.echo ""
If fso.FileExists(Ag(1)) = False Then
Wscript.echo "Zip doesn't exist so trying to Create"
Set ts = fso.OpenTextFile(Ag(0), 8, vbtrue)
If Err.Number <> 0 Then
Wscript.echo "Opening Dest " & Err.number & " " & Err.Description & " " & Err.Source
Err.Clear
End If
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip
If Err.Number <> 0 Then
Wscript.echo "Writing Dest " & Err.number & " " & Err.Description & " " & Err.Source
Err.Clear
End If
End If
Set DestFldr=objShell.NameSpace(Ag(1))
If Err.Number <> 0 Then
Wscript.echo "Creating Dest " & Err.number & " " & Err.Description & " " & Err.Source
Err.Clear
End If
Set SrcFldr=objShell.NameSpace(Ag(0))
If Err.Number <> 0 Then
Wscript.echo "Creating Source " & Err.number & " " & Err.Description & " " & Err.Source
Err.Clear
End If
wscript.echo DestFldr.Self.Name & " " & DestFldr.Self.Type & " " & DestFldr.Self.IsBrowsable & " " & DestFldr.Self.IsFileSystem
If Err.Number <> 0 Then
Wscript.echo Err.number & " " & Err.Description & " " & Err.Source
Err.Clear
End If
wscript.echo SrcFldr.Self.Name & " " & SrcFldr.Self.Type & " " & SrcFldr.Self.IsBrowsable & " " & SrcFldr.Self.IsFileSystem
If Err.Number <> 0 Then
Wscript.echo Err.number & " " & Err.Description & " " & Err.Source
Err.Clear
End If
Set FldrItems=SrcFldr.Items
For Each Itm in FldrItems
wscript.echo Itm.Name & " " & Itm.IsBrowsable & " " & Itm.IsFileSystem
Next
DestFldr.CopyHere FldrItems, &H10001210
Msgbox "Finished"这是输出
C:\Users\User>cscript //nologo "C:\Users\User\Desktop\David\Documents\Assorted\Scripts\UnZip - Copy.vbs" C:\symbols c:\file1.zip
C:\symbols Is Drive False Is Folder True Is File False
c:\file1.zip Is Drive False Is Folder False Is File False
Zip doesn't exist so trying to Create
Opening Dest 70 Permission denied Microsoft VBScript runtime error
Writing Dest 424 Object required Microsoft VBScript runtime error
424 Object required Microsoft VBScript runtime error
symbols File folder False True
wkernel32.pdb False True
wntdll.pdb False True显示我没有创建它的权限。
C:\Users\User>cscript //nologo "C:\Users\User\Desktop\David\Documents\Assorted\Scripts\UnZip - Copy.vbs" C:\symbols c:\file2.zip
C:\symbols Is Drive False Is Folder True Is File False
c:\file2.zip Is Drive False Is Folder False Is File False
424 Object required Microsoft VBScript runtime error
symbols File folder False True
wkernel32.pdb False True
wntdll.pdb False True显示文件不存在。
这是起作用的时候。
"C:\Users\User\Desktop\David\Documents\Assorted\Scripts\UnZip //nologo - Copy.vbs“C:\符号是驱动器,C:\符号是驱动器,假是文件夹,真是文件,虚假是c:\file.zip,是驱动器,虚假是文件夹,是文件
file.zip压缩(压缩)文件夹真真符号文件文件夹假真wkernel32.pdb假真wntdll.pdb假真
我已经改变了选择而不是回复。请看这里的名单。
https://stackoverflow.com/questions/38598289
复制相似问题