我正在做一些研究,以找出最好和最有效的方法。 我需要在多個Window服務器/計算機上執行遠程腳本(當我們構建它們時)。在ASP.net中運行遠程VBScript的最佳方法是什麼? WMI或PsExec?
我有一個Web應用程序將自動執行此任務,我目前有我的原型工作使用PsExec來執行遠程腳本。這需要在系統上安裝PsExec。一位同事建議我應該使用WMI。
我在WMI中做了一些研究,但是找不到我要找的東西。 我想要將腳本上傳到服務器並執行它並讀取結果,或者已經在服務器上有腳本並執行它並讀取結果。儘管如此,我寧願選擇第一個選項!
哪個比較理想,PsExec還是WMI?
僅供參考,這是我的原型PsExec代碼。此腳本僅執行一個小腳本來獲取Windows操作系統和Service Pack Info。
Protected Sub windowsScript(ByVal COMPUTERNAME As String)
' Create an array to store VBScript results
Dim winVariables(2) As String
nameLabel.Text = Name.Text
' Use PsExec to execute remote scripts
Dim Proc As New System.Diagnostics.Process
' Run PsExec locally
Proc.StartInfo = New ProcessStartInfo("C:\Windows\psexec.exe")
' Pass in following arguments to PsExec
Proc.StartInfo.Arguments = COMPUTERNAME & " -s cmd /C c:\systemInfo.vbs"
Proc.StartInfo.RedirectStandardInput = True
Proc.StartInfo.RedirectStandardOutput = True
Proc.StartInfo.UseShellExecute = False
Proc.Start()
' Pause for script to run
System.Threading.Thread.Sleep(1500)
Proc.Close()
System.Threading.Thread.Sleep(2500) 'Allows the system a chance to finish with the process.
Dim filePath As String = COMPUTERNAME & "\TTO\somefile.txt"
'Download file created by script on Remote system to local system
My.Computer.Network.DownloadFile(filePath, "C:\somefile.txt")
System.Threading.Thread.Sleep(1000) ' Pause so file gets downloaded
''Import data from text file into variables
textRead("C:\somefile.txt", winVariables)
WindowsOSLbl.Text = winVariables(0).ToString()
SvcPckLbl.Text = winVariables(1).ToString()
System.Threading.Thread.Sleep(1000)
' ''Delete the file on server - we don't need it anymore
Dim Proc2 As New System.Diagnostics.Process
Proc2.StartInfo = New ProcessStartInfo("C:\Windows\psexec.exe")
Proc2.StartInfo.Arguments = COMPUTERNAME & " -s cmd /C del c:\somefile.txt"
Proc2.StartInfo.RedirectStandardInput = True
Proc2.StartInfo.RedirectStandardOutput = True
Proc2.StartInfo.UseShellExecute = False
Proc2.Start()
System.Threading.Thread.Sleep(500)
Proc2.Close()
' Delete file locally
File.Delete("C:\somefile.txt")
End Sub