How to pass an argument that starts with “//” to a wsh script?

China☆狼群 提交于 2019-12-01 04:27:24
cscript //E:JScript //nologo "%~f0" // %*

Pass a double slash to end the cscript own argument parsing.

note: I don't know if it is documented anywhere, but tested on windows 7 and 10

Test script:

Option Explicit

Dim argument

    For Each argument In WScript.Arguments
        WScript.Echo "argument: " & argument
    Next 

    For Each argument In WScript.Arguments.Named
        WScript.Echo "Named: " & argument
    Next 

    For Each argument In WScript.Arguments.UnNamed
        WScript.Echo "UnNamed: " & argument
    Next 

Output (sorry, spanish locale):

W:\>cscript //nologo test.vbs //test
Error de entrada: Opción desconocida "//test" especificada.

W:\>cscript //nologo test.vbs // //test /one two
argument: //test
argument: /one
argument: two
Named: /test
Named: one
UnNamed: two

W:\>cscript test.vbs // //nologo //test /one two
Microsoft (R) Windows Script Host versión 5.812
Copyright (C) Microsoft Corporation. Reservados todos los derechos.

argument: //nologo
argument: //test
argument: /one
argument: two
Named: /nologo
Named: /test
Named: one
UnNamed: two

W:\>

It works with named arguments after all.

WScript.Echo(WScript.Arguments.Named.Item("test"));

and

cscript myscript.wsf /test:"//test"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!