This thread https://stackoverflow.com/questions/9074476/is-it-possible-to-embed-and-execute-vbscript-within-a-batch-file-without-using-a/38600712#38600712概述了如何编写可能包含多种脚本语言组合的批处理混合程序,例如批处理、VBS、JScript、PowerShell 等。问题是,批处理混合程序是否将“外来”语言块视为“函数”,即调用这些块可能包括像常规和延迟扩展批处理变量这样的参数,这些参数像%1、%2等通常的参数一样被引用?
下面的示例显示了解压缩文件任务中的方法,同时使用this https://stackoverflow.com/questions/21704041/creating-batch-script-to-unzip-a-file-without-additional-zip-tools文件解压代码,但在 Win10 64 位中出现错误 - 为什么?请注意,链接文件解压缩代码给出了error https://stackoverflow.com/questions/38598289/unzip-file-error-when-using-vbs-script-in-windows-10/38600861?noredirect=1#comment64591878_38600861在 Win 10 中运行时也是如此,但不同。
<!-- : Begin batch script
@echo off
set "dir=C:\Temp\" & set "file=%USERPROFILE%\Downloads\archive.zip\"
cscript //nologo "%~f0?.wsf" "%dir%" "%file%"
exit /b
----- Begin wsf script --->
<job><script language="VBScript">
set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(%1) Then
fso.CreateFolder(%1)
End If
set objShell = CreateObject("Shell.Application")
set FilesInZip = objShell.NameSpace(%2).items
objShell.NameSpace(%1).CopyHere(FilesInZip)
set fso = Nothing
set objShell = Nothing
</script></job>
:: Error
..\test.bat?.wsf(9, 8) Microsoft VBScript compilation error: Invalid character
在 vbscript 中,第一个参数是:wscript.Arguments(0)
第二个参数是:wscript.Arguments(1)
所以,你应该这样写:
`
----- Begin wsf script --->
<job><script language="VBScript">
set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(wscript.Arguments(0)) Then
fso.CreateFolder(wscript.Arguments(0))
End If
set objShell = CreateObject("Shell.Application")
set FilesInZip = objShell.NameSpace(wscript.Arguments(1)).items
objShell.NameSpace(wscript.Arguments(0)).CopyHere(FilesInZip)
set fso = Nothing
set objShell = Nothing
</script></job>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)