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