这是我在这里的第一个问题,因为虽然我已经搜索了至少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变量格式。
答案 0 :(得分:2)
错误引发因为你没有将任何参数传递给vbs文件,并且它没有被传递,因为当你生成computers.bat
时你正在使用%1
(:number
的第一个参数} subroutine)作为参数,但在call :number
中没有任何参数。
此外,递增计算机编号未显示在computers.bat
中,因为delayedexpansion未激活。当执行到达一行或一个块(括号内的代码)时,解析器用变量中的值替换变量读取,然后开始执行它。由于变量的值在块内部发生变化,但没有变量读取,只有之前变量的值开始执行,因此看不到变化。您需要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
答案 1 :(得分:0)
Dim env
Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
WScript.Echo oEnvironment("Computer1")