0
我想将下面的命令的结果分配给一个变量。目标是获取PID号码。试图删除所有空格,制表符,回车使用VBScript
SERVICE_NAME: msftpsvc
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 7888
FLAGS :
如果大家有更好的想法让我知道。但我试图删除所有的空格,制表符,回车符等等,以便我可以搜索“PID:”字符串和“FLAGS”,然后复制PID编号。
我还没有能够删除空格,并在一个单一的字符串中的一切。这里是我的代码:
Dim wshShell
Set wshShell = WScript.CreateObject("WScript.Shell")
Dim CommandToRun, ScriptStdOut, ScriptStdErr, ExitCode
Dim results
CommandToRun = "sc.exe queryex msftpsvc"
ExitCode = ExecScript(CommandToRun)
results = Replace(ScriptStdOut, vbCrLf, "") 'this works
results = Replace(results, vbTab, "") 'nothing happens
results = Trim(results) 'nothing happens
Function ExecScript(Command)
Dim WshShellExec
Set WshShellExec = WshShell.Exec("cmd /c " & Command)
Dim ErrorRead
ScriptStdOut=""
ScriptStdErr=""
Do While WshShellExec.Status = 0
Do While Not WshShellExec.StdOut.AtEndOfStream
ScriptStdOut=ScriptStdOut&WshShellExec.StdOut.ReadAll()
Loop
Do While Not WshShellExec.StdErr.AtEndOfStream
ErrorRead = true
ScriptStdErr=ScriptStdOut&WshShellExec.StdErr.ReadAll()
Loop
Loop
ExecScript=WshShellExec.ExitCode
wscript.echo ScriptStdOut
Set WshShellExec=nothing
End Function
谢谢
谢谢你,这是一个更好的解决方案! – Max 2014-12-01 23:44:10