[英]VBScript Error “End of Statement” in .vbs File with SendKeys Method
[英].vbs(5, 1) Microsoft VBScript runtime error: Subscript out of range Error:800A0009
这是我在这里的第一个问题,因为虽然我已经搜索了至少15个不同的其他帖子来解答我的问题,但没有人能得到答案。 请帮忙!
问题:如何修复错误:800A0009 ?
详细信息:我正在创建一个小程序,它收集所有本地计算机并向它们发送所有要播放的音频文件。 此外,如果有人知道,我需要知道如何强制发送。 最后,我首先运行“Get Computers.bat”。
我的代码:
~~~~~~ VBS FILE(Remote Speak.vbs)~~~~~~~~~~~~~~~~~~~
(获取包含计算机网络名称的变量传输,并使用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)~~~~~~~~~~~
(收集计算机名称并使用网络视图分配每个计算机名称,将“\\”过滤到计算机%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)
(我自己编制的计算机,但它们通常采用这种格式。)
@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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~详情~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
1.)Temp.bat实际上只是暂时的,它被删除了,正如你所看到的,几乎在它创建之后,它只是在它突然退出循环之后保持%num%的值,因为它没有显示“你拥有网络上%num%的计算机!“ 正确。
2.)除了顶行之外,不要过多担心VBScript文件:
Option Explicit
Dim args, strOut
set args = Wscript.arguments
strOut= args(0)
IP = strOut
3.)我的主要问题是我试图找到一种安全的方法让“Computers.bat”调用“Remote Speak.vbs”文件并将其批处理变量设置为与各个计算机完全相同的名称,以VBScript变量格式。
错误引发因为您没有将任何参数传递给vbs文件,并且它没有被传递,因为当您生成computers.bat
您使用%1
( :number
子例程的第一个参数)作为参数,但在call :number
没有任何参数。
此外,递增计算机数量并不所示computers.bat
因为delayedexpansion不活跃。 当执行到达一行或一个块(括号内的代码)时,解析器用变量中的值替换变量读取,然后开始执行它。 由于变量的值在块内部发生变化,但没有变量读取,只有变量的值在开始执行之前 ,没有看到变化。 您需要setlocal enabledelayedexpansion
才能启用它,并在需要时将%var%
更改为!var!
指示解析器需要延迟变量读取,而不是在初始解析时替换。
无论如何,您的代码不会使用它。 if exist %%f
什么? 为什么loop
?
对于第三个问题, WshShell
对象的Environment
属性允许您读取所需的变量
Dim env
Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
WScript.Echo oEnvironment("Computer1")
这是对代码的快速清理。 从您的问题来看,这似乎只是一个起点。 根据需要进行调整。
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
@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.