如何将参数传递给vbscript?

时间:2018-11-13 20:46:00

标签: cmd vbscript

我有一个运行多个Tor连接的VBS:

proxycount = 3
countries = ""

Set FSO = CreateObject("Scripting.FileSystemObject") 
Set f = FSO.OpenTextFile("proxyList.txt", 2, True) 

For i=0 To proxycount-1 Step 1

    Port = 9000 + i
    CPort = 8000 + i

    If Not (countries = "") Then
            countries = " -ExitNodes " & countries
    End If

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "data\tor.exe -f data\torrc -SocksPort " & Port & " -ControlPort " & CPort & " -DataDirectory data\torf" & i & countries, 0
    WshShell = Null
    f.WriteLine "127.0.0.1:" & Port 

Next

f.Close 

它很好用,但是当我尝试传递proxycount作为参数时: CMD 它停止工作:

countries = ""

Set FSO = CreateObject("Scripting.FileSystemObject") 
Set f = FSO.OpenTextFile("proxyList.txt", 2, True) 

For i=0 To WScript.Arguments(0)-1 Step 1

    Port = 9000 + i
    CPort = 8000 + i

    If Not (countries = "") Then
            countries = " -ExitNodes " & countries
    End If

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "data\tor.exe -f data\torrc -SocksPort " & Port & " -ControlPort " & CPort & " -DataDirectory data\torf" & i & countries, 0
    WshShell = Null
    f.WriteLine "127.0.0.1:" & Port 

Next

f.Close 

在此行中出现错误“字符串17,符号2。找不到文件”。

WshShell.Run "data\tor.exe -f data\torrc -SocksPort " & Port & " -ControlPort " & CPort & " -DataDirectory data\torf" & i & countries, 0

我在做什么错?我不知道错误在哪里。

1 个答案:

答案 0 :(得分:1)

在开头添加此行可解决问题:

WshShell.CurrentDirectory = FSO.GetParentFolderName(WSH.ScriptFullName)