0

私はC#コーディングが初めてです。次のことを手伝ってください。よろしくお願いします..!!!

私は次のことを試みています:

リモート サーバーでバッチ ファイルを実行する小さな C# アプリを開発しています。コードは次のとおりです。サーバーのほとんどは Windows 2008 64 ビットです。サーバーに RDP を実行すると、エラーなしでバッチ ファイルを実行できますが、実行しようとすると次のコードを使用すると、機能せず、例外はスローされませんが、結果はありません。

私のバッチファイルには次のコマンドが含まれています:

@ECHO off 
echo Running Remote Commands 
date/t 
time /t 
COPY "\\xt0022\I$\abc\RemoteProcess\testcopy.bat" D:\ab\
date/t 
time /t 

-

try
{
    string remotemachine = "Server1";

    object[] theProcessToRun = { "D:\\ab\\test2.bat" };
    ConnectionOptions theConnection = new ConnectionOptions();
    theConnection.Impersonation = ImpersonationLevel.Impersonate;
    theConnection.EnablePrivileges = true;
    ManagementScope theScope = new ManagementScope("\\\\" + remoteMachine + "\\root\\cimv2", theConnection);
    ManagementClass theClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
    theClass.InvokeMethod("Create", theProcessToRun);

}
catch (Exception ex)
{

}

コードをデバッグすると、「派生 = 関数の評価がタイムアウトしました」と表示されます。

これを RUNAS で実行する必要がありますか? はいの場合..誰かがそれらのコードまたはメソッドで私を助けることができます..?

皆さん、ありがとうございました..!

4

1 に答える 1

1

ProcessStartInfoを調べましたか?

ProcessStartInfo startInfo = new ProcessStartInfo("PsExec.exe");
startInfo.Arguments = @"\\<computername -u <username> -p <password> -i c:\\test.bat";
Process.Start(startInfo);

これがCodeProject.comの記事で、あなたと同じようにWMIを使用してリモートプロセスを作成します。完全なソースが利用可能です。

http://www.codeproject.com/Articles/31113/Create-a-Remote-Process-using-WMI-in-C

これはばかげた質問かもしれませんが、タイムアウトは何に設定されていますか?小さすぎる場合は、それが原因である可能性があります。

于 2012-05-09T20:20:00.420 に答える