vbs(5,1)微软VBScript运行时错误:下标超出范围错误:800A0009

时间:2021-07-23 16:42:04

This is my first question on here, because, although I have searched at least 15 different other posts for the answer to my issue, none have the answer. Please help!

这是我在这里的第一个问题,因为尽管我已经搜索了至少15个不同的帖子来寻找我的问题的答案,但是没有一个人知道答案。请帮助!

QUESTION: How do I fix Error:800A0009?

问题:我如何修正错误:800A0009?

DETAILS: I am creating a small program that gathers all local computers and sends them all an audio file to be played. Also, I need to know how to force send, if anyone knows. Lastly, I first run "Get Computers.bat".

细节:我正在创建一个小程序,收集所有本地计算机,并向它们发送一个要播放的音频文件。而且,如果有人知道,我还需要知道如何强制发送。最后,我第一次运行“Get Computers.bat”。

My Code:

我的代码:

~~~~~~VBS FILE(Remote Speak.vbs)~~~~~~~~~~~~~~~~~~~

~ ~ ~ ~ ~ ~根据文件(远程Speak.vbs)~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

(Obtains variable transferred which contains network name of a computer, and sends it a file to be play using SAPI)

(获取包含计算机网络名称的传输变量,并使用SAPI向其发送要播放的文件)

'get ip    
Option Explicit    
Dim args, strOut   
set args = Wscript.arguments    
strOut= args(0)    
IP = strOut

'get MSG    
MSG = InputBox("Type what you want the PC to say:", "Remote Voice Send By X BiLe", "")

If MSG = "" Then WScript.quit: Else

'vbs command to send

A = "on error resume next" & VBCRLF & _    
"CreateObject(""SAPI.SpVoice"").speak " & """" & MSG & """" & VBCRLF & _    
"CreateObject(""Scripting.FileSystemObject"").DeleteFile (""C:\Voice1.vbs"")"

' Create the vbs on remote C$    
CreateObject("Scripting.FileSystemObject").OpenTextFile("\\" & ip & "\C$\Voice1.vbs",2,True).Write A

' Run the VBS through Wscript on remote machine via WMI Object Win32_Process    
B = GetObject("winmgmts:\\" & IP & "\root\cimv2:Win32_Process").Create("C:\windows\system32\wscript.exe ""C:\Voice1.vbs""", null, null, intProcessID)

~~~BATCH PRIMARY (Get Computers.bat)~~~~~~~~~~~

~ ~ ~一批初级(Computers.bat)~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

(Gathers computer names and assign each one, using net view, filtering the "\" to Computer%num%. Also, :tempcall is just an error handler.)

(收集计算机名称并分配每个名称,使用net view,将“\”过滤到计算机%num%。另外,:tempcall只是一个错误处理程序。

@echo off    
cls    
set num=1    
echo @echo off > Computers.bat    
if "%1"=="loop" (    
for /f "delims=\ tokens=*" %%a in ('net view ^| findstr /r "^\\\\"') do (    
set comp=%%a    
call :number    
if exist %%f exit    
)    
goto :eof    
)    
cmd /v:on /q /d /c "%0 loop"    
:tempcall    
call temp.bat    
echo.    
echo.    
echo.    
echo You have %num%computers on your network!    
pause>nul    
del /q temp.bat    
start Computers.bat    
exit    
:number    
if %comp% == "" (    
goto :tempcall    
) else (    
echo set Computer%num%=%comp% >> Computers.bat    
echo cscript "Remote Speak.vbs" %1 >> Computers.bat    
echo call "Remote Speak.vbs" >> Computers.bat    
echo set num=%num% > temp.bat    
echo Computer%num%: %comp%    
set /a num=%num% + 1    
)

BATCH SECONDARY (Computers.bat)

批处理二级(Computers.bat)

(The computers I made up off the top of my head, but they are generally in that format.)

(我用电脑做的电脑,但它们一般都是那种格式。)

@echo off    
set Computer1=040227-CYCVN1                                              
cscript "Remote Speak.vbs" //NoLogo > log.txt    
set Computer1=051448-YZVN2                                                             
cscript "Remote Speak.vbs" //NoLogo > log.txt    
pause>nul

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END DETAILS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~结束细节~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

1.) Temp.bat is literally just temporary, it's deleted, as you can see, almost immediately after it's created, it simply holds the value of %num% after it breaks out of the loop, because it didn't show "You have %num%computers on your network!" correctly.

1)。bat实际上只是临时的,它被删除了,正如您所看到的,几乎在创建之后,它只是在跳出循环之后保持%num%的值,因为它没有正确地显示“您的网络上有%num%的计算机!”

2.) Don't worry too much about the VBScript file except for the top lines:

2)。不要太担心VBScript文件,除了上面几行:

Option Explicit

Dim args, strOut

set args = Wscript.arguments

strOut= args(0)

IP = strOut

3.) My main issue is that I am trying to find a safe way to have "Computers.bat" call the "Remote Speak.vbs" file and set it's batch variables to be the exact same names to refer to the individual computers, in VBScript variable format.

3)。我的主要问题是我正在寻找一种安全的方式来拥有“电脑”。蝙蝠叫“遥控器”。vbs文件,并将其批处理变量设置为完全相同的名称,以VBScript变量格式引用各个计算机。

1 个解决方案

#1


2  

The error raises because you are not passing any argument to the vbs file, and it is not passed because when you generate computers.bat you are using %1 (the first argument to the :number subroutine) as a parameter, but in call :number there is not any parameter.

错误会增加,因为您没有将任何参数传递给vbs文件,并且它没有通过,因为当您生成计算机时。bat,您正在使用%1 (:number子例程的第一个参数)作为参数,但是在call:number中没有任何参数。

Also, the incrementing computer number is not shown in computers.bat because delayedexpansion is not active. When execution reaches a line or block (the code inside parenthesis), the parser replaces variable reads with the value in the variable and then starts to execute it. As the value of the variable changes inside the block, but there is no variable read, only the value of the variable before starting to execute, changes are not seen. You need to setlocal enabledelayedexpansion to enable it and, where needed, change %var% to !var! to indicate the parser that the variable read needs to be delayed, not replaced at initial parse time.

此外,递增的计算机编号也不显示在计算机中。蝙蝠,因为延迟反应不活跃。当执行到达行或块(括号内的代码)时,解析器将变量读取替换为变量中的值,然后开始执行。由于变量的值在块内部发生变化,但是没有读取变量,只有在开始执行之前变量的值,所以不会看到变化。您需要setlocal enabledelayedexpansion来启用它,并在需要时将%var% to !var!为了指示解析器读取的变量需要延迟,而不是在初始解析时替换。

And anyway, your code does not use it. And what is if exist %%f? And why the loop?

无论如何,你的代码不使用它。如果存在%f是多少?为什么循环?

For your third question, the Environment property of the WshShell objects lets you read the required variables

对于第三个问题,WshShell对象的环境属性允许您读取所需的变量

Dim env
    Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
    WScript.Echo oEnvironment("Computer1")

This is a fast cleanup of your code. From your question it seems this is only the starting point. Adapt as needed.

这是对代码的快速清理。从你的问题来看,这似乎只是一个起点。根据需要调整。

RemoteSpeak.vbs

RemoteSpeak.vbs

Option Explicit    

If WScript.Arguments.Count < 1 Then 
    WScript.Quit
End If

'get ip
Dim IP
    IP = WScript.Arguments.Item(0)

'get MSG    
Dim MSG
    MSG = InputBox("Type what you want the PC to say:", "Remote Voice Send By X BiLe", "")
    If MSG = "" Then 
        WScript.Quit
    End If

Dim A
    A = "on error resume next" & VBCRLF & _    
        "CreateObject(""SAPI.SpVoice"").speak " & """" & MSG & """" & VBCRLF & _    
        "CreateObject(""Scripting.FileSystemObject"").DeleteFile(WScript.ScriptFullName)"

' Create the vbs on remote C$    
    CreateObject("Scripting.FileSystemObject").OpenTextFile("\\" & IP & "\C$\Voice1.vbs",2,True).Write A

' Run the VBS through Wscript on remote machine via WMI Object Win32_Process    
Dim B
    B=GetObject("winmgmts:\\" & IP & "\root\cimv2:Win32_Process").Create("C:\windows\system32\wscript.exe ""C:\Voice1.vbs""", null, null, intProcessID)

getComputers.bat

getComputers.bat

@echo off    
    setlocal enableextensions enabledelayedexpansion
    cls    
    set "num=0"
    (   echo @echo off
        for /f "tokens=* delims=\" %%a in ('net view ^| findstr /r /c:"^\\\\"') do (
            set /a "num+=1"
            echo set "Computer!num!=%%a"
            echo cscript "RemoteSpeak.vbs" %%a
        )    
    ) > computers.bat

    echo You have %num% computers in your network
    pause > nul
    start Computers.bat
    endlocal
    exit /b 

#1


2  

The error raises because you are not passing any argument to the vbs file, and it is not passed because when you generate computers.bat you are using %1 (the first argument to the :number subroutine) as a parameter, but in call :number there is not any parameter.

错误会增加,因为您没有将任何参数传递给vbs文件,并且它没有通过,因为当您生成计算机时。bat,您正在使用%1 (:number子例程的第一个参数)作为参数,但是在call:number中没有任何参数。

Also, the incrementing computer number is not shown in computers.bat because delayedexpansion is not active. When execution reaches a line or block (the code inside parenthesis), the parser replaces variable reads with the value in the variable and then starts to execute it. As the value of the variable changes inside the block, but there is no variable read, only the value of the variable before starting to execute, changes are not seen. You need to setlocal enabledelayedexpansion to enable it and, where needed, change %var% to !var! to indicate the parser that the variable read needs to be delayed, not replaced at initial parse time.

此外,递增的计算机编号也不显示在计算机中。蝙蝠,因为延迟反应不活跃。当执行到达行或块(括号内的代码)时,解析器将变量读取替换为变量中的值,然后开始执行。由于变量的值在块内部发生变化,但是没有读取变量,只有在开始执行之前变量的值,所以不会看到变化。您需要setlocal enabledelayedexpansion来启用它,并在需要时将%var% to !var!为了指示解析器读取的变量需要延迟,而不是在初始解析时替换。

And anyway, your code does not use it. And what is if exist %%f? And why the loop?

无论如何,你的代码不使用它。如果存在%f是多少?为什么循环?

For your third question, the Environment property of the WshShell objects lets you read the required variables

对于第三个问题,WshShell对象的环境属性允许您读取所需的变量

Dim env
    Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
    WScript.Echo oEnvironment("Computer1")

This is a fast cleanup of your code. From your question it seems this is only the starting point. Adapt as needed.

这是对代码的快速清理。从你的问题来看,这似乎只是一个起点。根据需要调整。

RemoteSpeak.vbs

RemoteSpeak.vbs

Option Explicit    

If WScript.Arguments.Count < 1 Then 
    WScript.Quit
End If

'get ip
Dim IP
    IP = WScript.Arguments.Item(0)

'get MSG    
Dim MSG
    MSG = InputBox("Type what you want the PC to say:", "Remote Voice Send By X BiLe", "")
    If MSG = "" Then 
        WScript.Quit
    End If

Dim A
    A = "on error resume next" & VBCRLF & _    
        "CreateObject(""SAPI.SpVoice"").speak " & """" & MSG & """" & VBCRLF & _    
        "CreateObject(""Scripting.FileSystemObject"").DeleteFile(WScript.ScriptFullName)"

' Create the vbs on remote C$    
    CreateObject("Scripting.FileSystemObject").OpenTextFile("\\" & IP & "\C$\Voice1.vbs",2,True).Write A

' Run the VBS through Wscript on remote machine via WMI Object Win32_Process    
Dim B
    B=GetObject("winmgmts:\\" & IP & "\root\cimv2:Win32_Process").Create("C:\windows\system32\wscript.exe ""C:\Voice1.vbs""", null, null, intProcessID)

getComputers.bat

getComputers.bat

@echo off    
    setlocal enableextensions enabledelayedexpansion
    cls    
    set "num=0"
    (   echo @echo off
        for /f "tokens=* delims=\" %%a in ('net view ^| findstr /r /c:"^\\\\"') do (
            set /a "num+=1"
            echo set "Computer!num!=%%a"
            echo cscript "RemoteSpeak.vbs" %%a
        )    
    ) > computers.bat

    echo You have %num% computers in your network
    pause > nul
    start Computers.bat
    endlocal
    exit /b