0

私はこれのための最良かつ最も効率的な方法を見つけるためにいくつかの研究を行っています。いくつかのウィンドウサーバー/コンピューターでリモートスクリプトを実行する必要があります(それらを構築している間)。

このタスクを自動化するWebアプリケーションがあります。現在、プロトタイプを使用してPsExecを使用してリモートスクリプトを実行しています。これには、PsExecがシステムにインストールされている必要があります。同僚は、これにはWMIを使用する必要があると提案しました。

WMIで調査を行いましたが、探しているものが見つかりませんでした。スクリプトをサーバーにアップロードして実行して結果を読み取るか、サーバーにスクリプトを既にインストールして実行して結果を読み取る必要があります。私は最初のオプションを好みます!

PsExecとWMIのどちらがより理想的ですか?

参考までに、これは私のプロトタイプのPsExecコードです。このスクリプトは、WindowsOSおよびサービスパック情報を取得するための小さなスクリプトのみを実行しています。

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
4

2 に答える 2

0

はい、PsExecは断然最善のルートです。PsExecはRPCを使用してADMIN$共有にアクセスします。ただし、デフォルトのWin7のようにRPCが無効になっていて、WMIが有効になっいて、アカウントで読み取り/書き込みアクセスが可能な共有フォルダーがある場合は、数か月前にフランクホワイトが作成した回避策を使用できます。 cmd / c echo ... "アプローチ:

strCommand = "cmd / c echo myTextCommands> c:\ temp \ testscript.txt"

完全に肉付けされたVBScriptを確認するには、ここで私のソリューションを参照してください

于 2012-08-27T21:37:15.340 に答える
0

追加の調査から、このタイプのプロジェクトでは、PsExecが最適なルートであるように見えます。

于 2012-07-23T20:14:05.070 に答える