[英]How can I call a function in a vbscript with command line arguments?
我有一個腳本,可以遠程執行以查看程序是否正在運行。 它工作正常,但是我需要它來檢查多個服務器上的多個程序,並且我不想重寫它。 我試圖查看是否可以通過命令行在vbscript中調用該函數,以便可以使用1個腳本並在命令行中更改參數。
Function IsProcessRunning(strComputer, strProcess)
Dim Process, strObject
IsProcessRunning = 0
strObject = "winmgmts://" & strComputer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = 1
If IsProcessRunning = 1 Then
WScript.echo 1 & ": " & strProcess & " is currently running on " & strComputer
End If
Exit Function
End If
Next
WScript.echo 0 & ": " & strProcess " is NOT running on " & strComputer
End Function
我希望能夠通過cmd像這樣運行:run.vbs IsprocessRunning Server3 Program2.exe
UPDATE
為什么不使用WMIC
? 例如 在命令行中輸入:
wmic /node:server1 process where name='explorer.exe' get processid
在server1上獲取所有啟動的資源管理器進程ID。
資源
使用WScript.Arguments
屬性:
IsProcessRunning WScript.Arguments(0), WScript.Arguments(1)
Function IsProcessRunning(strComputer, strProcess)
Dim Process, strObject
IsProcessRunning = 0
strObject = "winmgmts://" & strComputer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase(Process.name) = UCase(strProcess) Then
IsProcessRunning = 1
WScript.echo 1 & ": " & strProcess & " is currently running on " & strComputer
Exit Function
End If
Next
WScript.echo 0 & ": " & strProcess & " is NOT running on " & strComputer
End Function
最好添加一些檢查,以便為腳本提供適當的命令行參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.