错误产生是因为您没有将任何参数传递给vbs文件,并且没有传递该参数,因为生成computers.bat
时您将%1
(:number
子例程的第一个参数)用作参数,但在call :number
中没有任何参数。
这是我在这里的第一个问题,因为尽管我至少搜索了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主要(Get Computers.bat)~~~~~~~~~~~
(使用网络视图收集计算机名称并分配每个名称,将“ \”过滤到Computer%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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ END细节~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~]]
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变量格式。
这是我在这里的第一个问题,因为尽管我至少搜索了15个其他帖子以找到问题的答案,但没有人找到答案。请帮忙!问题:如何修复错误:...
错误产生是因为您没有将任何参数传递给vbs文件,并且没有传递该参数,因为生成computers.bat
时您将%1
(:number
子例程的第一个参数)用作参数,但在call :number
中没有任何参数。
此外,由于延迟扩展未处于活动状态,因此增量计算机号未显示在computers.bat
中。当执行到达行或块(括号内的代码)时,解析器将变量读取值替换为变量中的值,然后开始执行它。由于变量的值在块内更改,但是没有读取变量,因此仅开始执行变量before
setlocal enabledelayedexpansion
并将其启用,并在需要时将%var%
更改为!var!
以指示解析器需要延迟读取变量,而不是在初始解析时替换。而且无论如何,您的代码不使用它。什么是if exist %%f
?以及为什么loop
?
关于第三个问题,Environment
对象的WshShell
属性使您可以读取所需的变量
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
Dim env
Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
WScript.Echo oEnvironment("Computer1")
错误产生是因为您没有将任何参数传递给vbs文件,并且没有传递该参数,因为生成computers.bat
时您将%1
(:number
子例程的第一个参数)用作参数,但在call :number
中没有任何参数。
Dim env
Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
WScript.Echo oEnvironment("Computer1")