在批处理中使用变量VBS混合动力车 [英] Using variables in batch & VBS hybrids

查看:98
本文介绍了在批处理中使用变量VBS混合动力车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

This thread outlines how to code batch hybrids that may include a combination of several scripting languages, such as batch, VBS, JScript, PowerShell, etc. The question is, whether a batch hybrid treats "foreign" language blocks as "functions", meaning calls to these blocks may include arguments like regular and delayed expansion batch variables, that are referenced as usual arguments like %1, %2, etc?

下面的示例显示了在不使用错误,但是会出现错误.

Example below shows the approach in the task of unzipping a file, while using this file unzip code, but it gives an error in Win10 64-bit - why? Note, the linked file unzip code gives an error as well when run in Win 10, but a different one.

<!-- : 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)

In vbscript the first argument is : wscript.Arguments(0)

第二个参数是:wscript.Arguments(1)

因此,您应该这样写: `

So,you should write it like that : `

----- 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>

这篇关于在批处理中使用变量VBS混合动力车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆