[英].vbs(5, 1) Microsoft VBScript runtime error: Subscript out of range Error:800A0009
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. 这是我在这里的第一个问题,因为虽然我已经搜索了至少15个不同的其他帖子来解答我的问题,但没有人能得到答案。 Please help! 请帮忙!
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)~~~~~~~~~~~~~~~~~~~ ~~~~~~ VBS FILE(Remote 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)~~~~~~~~~~~ ~~~ BATCH PRIMARY(Get Computers.bat)~~~~~~~~~~~
(Gathers computer names and assign each one, using net view, filtering the "\\" to Computer%num%. Also, :tempcall is just an error handler.) (收集计算机名称并使用网络视图分配每个计算机名称,将“\\”过滤到计算机%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) BATCH SECONDARY(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!" 1.)Temp.bat实际上只是暂时的,它被删除了,正如你所看到的,几乎在它创建之后,它只是在它突然退出循环之后保持%num%的值,因为它没有显示“你拥有网络上%num%的计算机!“ correctly. 正确。
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.)我的主要问题是我试图找到一种安全的方法让“Computers.bat”调用“Remote Speak.vbs”文件并将其批处理变量设置为与各个计算机完全相同的名称,以VBScript变量格式。
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文件,并且它没有被传递,因为当您生成computers.bat
您使用%1
( :number
子例程的第一个参数)作为参数,但在call :number
没有任何参数。
Also, the incrementing computer number is not shown in computers.bat
because delayedexpansion is not active. 此外,递增计算机数量并不所示computers.bat
因为delayedexpansion不活跃。 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!
您需要setlocal enabledelayedexpansion
才能启用它,并在需要时将%var%
更改为!var!
to indicate the parser that the variable read needs to be delayed, not replaced at initial parse time. 指示解析器需要延迟变量读取,而不是在初始解析时替换。
And anyway, your code does not use it. 无论如何,您的代码不会使用它。 And what is if exist %%f
? if exist %%f
什么? And why the loop
? 为什么loop
?
For your third question, the Environment
property of the WshShell
objects lets you read the required variables 对于第三个问题, WshShell
对象的Environment
属性允许您读取所需的变量
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.