Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 无法使用VB脚本在多个系统上运行进程_Vbscript - Fatal编程技术网

Vbscript 无法使用VB脚本在多个系统上运行进程

Vbscript 无法使用VB脚本在多个系统上运行进程,vbscript,Vbscript,我有VB脚本在远程机器上运行进程。 但它在第一台机器(导入文本文件中的第一个主机名)上运行良好 这是剧本 [让我解释一下:我在文本文件(C:\computers.txt)中有很多系统,并试图运行cmd来配置HP remote board上的用户 我可以看到结果(成功),它在第一台主机上工作正常,然后我可以看到错误“进程无法访问该文件,因为它正被另一个进程使用”。] 我的问题是,它应该在所有的机器上运行,没有任何错误,有人可以告诉我在下面的脚本中插入绕过行的位置 也请建议我写剧本的可行方法 你能帮

我有VB脚本在远程机器上运行进程。 但它在第一台机器(导入文本文件中的第一个主机名)上运行良好

这是剧本

[让我解释一下:我在文本文件(C:\computers.txt)中有很多系统,并试图运行cmd来配置HP remote board上的用户

我可以看到结果(成功),它在第一台主机上工作正常,然后我可以看到错误“进程无法访问该文件,因为它正被另一个进程使用”。]

我的问题是,它应该在所有的机器上运行,没有任何错误,有人可以告诉我在下面的脚本中插入绕过行的位置

也请建议我写剧本的可行方法

你能帮帮我吗

Set WSHShell = WScript.CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")

Set oTS = oFS.OpenTextFile("C:\computers.txt")

Do Until oTS.AtEndOfStream

strCompname = oTS.ReadLine

WshShell.Run "cmd.exe /v:on /k (set MYDIR=C:\Program Files\HP\hponcfg\) & cd /d ""!MYDIR!"" & HPONCFG.exe  /f \\transfer\transfer\c5180150\Add_User.xml /l log.txt > output.txt" 

Loop

Set wshShell = Nothing

wscript.quit


'close the text file

oTS.Close

为什么不使用wmic来做呢

wmic /node:@computerlist.txt process call create '"c:\\windows\\system32\\cmd.exe" /c "C:\\Program Files\\HP\\hponcfg\\HPONCFG.exe" /f \\\\transfer\\transfer\\c5180150\\Add_User.xml /l log.txt'
可能会(我无法测试)

Computerlist.txt可以是名称或ip

127.0.0.1
computername
命令字符串,因为它们由C程序解析,需要用反斜杠转义反斜杠

如果要在计算机上输出,请在WMIC上使用重定向或使用WMIC的追加开关(
/Append:“filename.txt”

这里有4个例子展示了wmic的不同能力

wmic /node:"@%userprofile%\desktop\ComputerName.txt" /output:"%userprofile%\desktop\NicSpeed.html" /failfast:on nic where (PhysicalAdapter=TRUE and Speed!=100000000) get systemname,speed,caption /format:htable
wmic /node:"@%userprofile%\desktop\ComputerName.txt" /output:"%userprofile%\desktop\NicSpeed.html" /failfast:on FSDIR get /format:hform
wmic /output:clipboard process where "Name='wscript.exe'" get commandline,ParentProcessId /format:List
wmic /node:"@%userprofile%\desktop\ComputerName.txt" /output:"%userprofile%\desktop\Alias.html" /failfast:on alias get /format:hform 

您在代码中的何处使用变量“strCompname”“是的,你明白我的意思。。我试着在cmd中使用它,但出现语法错误。就这样离开了。我不知道在哪里调用这个函数。是的,如果你能告诉我在我的cmd中在哪里添加单词strCompname!那会解决我的问题。。如果没有,请建议…您好,您正在谈论的只是一行做这个功能?如果是这样,如何读取系统名称?wmic/node:@computerlist.txt进程调用create''c:\\windows\\system32\\cmd.exe”/c“c:\\Program Files\\HP\\hponcfg\\hponcfg.exe”/f\\\\\transfer\\transfer\\c5180150\\Add_User.xml/l log.txt'是一行。如果你读了我的答案,我会说ComputerName,无论是名称还是IP地址(你可以像我在发布的示例文件中那样混合)都在computerlist.txt中(@表示它是一个名称文件,没有@表示它是远程系统名称)。此外,WMIC使用WMI,vbscript也可以使用WMI(此处既有WMIC标记,也有WMI标记)。因此,请尝试
WMIC/?
WMIC process/?
WMIC process call/?
WMIC process get/?
WMIC process set/?
(如果可以设置任何内容),输出也可以是
/format:CSV
/format:table
/format:HForm
(网页列表)。还有
列表
HTable
XML
。如果您想在其他系统上键入和查看命令,请访问Microsoft网站上的psexec。wmic的任何远程命令在远程计算机上都是不可见的(它出现在任务管理器中),您可以在运行本地命令时看到命令的运行。