2013-04-30 16 views
8

私のAsp.Net WebアプリケーションからPSExecを実行して、リモートサーバーに接続しようとしています。何らかの形で、資格情報が設定されていない"Access Denied Error -5"が与えられ、PSEXECコマンドの資格情報を設定すると"2250 Network connection could not be found"となります。私はサーバー上の管理者です。Windows authentication and Asp.Net Impersonationが有効になっています(IIS7.5)。もっと興味深いことに、私がconsole applicationからこれを実行しようとした場合でも、ちょうどcommand promptを使用しても、うまく動作します。私はテストとしてping操作をしようとしています。ここでAsp.Net Webアプリケーションからsysinternals PSExecを使用してスクリプトを実行

  var startInfo = new ProcessStartInfo{ 
       CreateNoWindow = true, 
       UseShellExecute = false, 
       FileName = FilePath, 
       Arguments = CommandArgs 
      } 

      Process vsCommandProcess = Process.Start(startInfo); 

      vsCommandProcess.WaitForExit(); 
      var exitCode = vsCommandProcess.ExitCode; 
      if (vsCommandProcess.ExitCode != 0) 
      { 
       ...rest of the code 

: - - :

FilePath --> C:\pstools\psexec.exe 
Arguments --> \\servername -accepteula -u domain\userName -p password ipconfig (1) 
       \\servername -accepteula ipconfig (2)   

(1) Gives Error 2250 (2) gives Error 5 

同じコマンドおよびコードは、コンソールアプリケーションで動作します

は、ここに私のコードスニペットです。だから私は間違いなく、マシンにリモートに資格情報を引き継ぐことはできませんAsp.netアプリケーションとは何かを信じています。私イベントはstartInfo.LoadUserProfileを試しましたが、役に立たなかった。

あなたのお手伝いをお待ちしております。私は同様の質問を調べようとしましたが、私が直面している問題の解決策を見つけることができませんでした。

+0

1コンソールで動作し、asp Webアプリケーションでは動作しない場合は、セキュリティ上の問題のようです。 2 .netバージョンが正しいかどうかを確認しましたか? .NET 2.0でIIS上でアプリケーションプールを実行しようとしました(私はこの問題を今日抱えていました)。 – gartenabfall

+0

私はドットネットバージョン4.0を使用しています。はい、これ以上の認証トークンのように思われます.... – PSL

+0

IISはコマンドプロンプトと同じユーザー権限で実行されていますか? – Powerslave

答えて

2

psexecを処理しないことを検討してください。 WMIに行くことは直接間違って何が起こっているかにより洞察力を与えることがあります。あなたはまだ偽装の問題に実行する場合

var connOpts = new ConnectionOptions() 
{ 
// Optional, default is to use current identity 
    Username = "username", 
    Password = "password" 
}; 

// create a handle to the Win32_Process object on the remote computer 
ManagementScope mgmtScope = new ManagementScope(@"\\servername\root\cimv2", connOpts); 
ManagementClass w32Process = new ManagementClass(mgmtScope, 
    new ManagementPath("Win32_Process"), new ObjectGetOptions()); 

// create the process itself 
object[] createArgs = new object[] { 
    // [in] string CommandLine, 
    "notepad.exe", 
    // [in] string CurrentDirectory, 
    null, 
    // [in] Win32_ProcessStartup ProcessStartupInformation, 
    null, 
    // [out] uint32 ProcessId 
    0}; 

var result = (int)w32Process.InvokeMethod("Create", createArgs); 

switch (result) 
{ 
    case 0: /* no-op, successful start */ break; 
    case 2: throw new Exception("Access Denied"); 
    case 3: throw new Exception("Insufficient Privilege"); 
    case 8: throw new Exception("Unknown failure"); 
    case 9: throw new Exception("Path not found"); 
    case 21: throw new InvalidOperationException("Invalid Parameter"); 
} 

は、IISが正しく設定されていることを確認するためにHttpContext.Current.User.Identityの内容をダンプすると便利かもしれません。さらに、Kerberos(Negotiate/SPNEGO経由)を使用している場合は、allow the machine to delegate identityが必要な場合があります。マシンが接続するSPNを知っている場合、制約付き委任を使用できますが、多くの場合、ターゲットが事前にわかっていない場合は、制約のない委任を許可する必要があります。


注:あなただけでipconfigを実行するコンピュータにリモート処理されている場合、あなたは呼び出し元のコンピュータにSTDOUT出力を取得しようとして混乱することなく、WMI経由で同じ情報を得ることができます。 Win32_NetworkAdapterConfigurationクラスを見てください。

関連する問題