2012-01-19 5 views
1

PowerShellラン空間からvbscriptを実行しようとしているサイトがあります(奇妙な音ですが、思った最も簡単な方法でした)。私の問題は、PowerShellスクリプトがローカルのマシンアカウントとして実行されていて、それを実行しているユーザーではありません。これを修正する上での助けに感謝します。 http://support.microsoft.com/kb/306158にあるimpersonationcontextを使ってみましたが、失敗しました。前もって感謝します。次のようにC#Powershell Runspaceは、マシンアカウントではなく、ユーザーとして実行します。

protected void btnRemMaint_Click(object sender, EventArgs e) 
    { 
     txtOutput.Text = ""; 
     txtOutput.Text = "Remove Maintenance Results"; 
     txtOutput.Text += Environment.NewLine; 

     string servers; 
     servers = txtServers.Text.Replace(Environment.NewLine, ","); 

     while (servers[servers.Length - 1].ToString() == ",") 
      servers = servers.Substring(0, servers.Length - 1); 

     System.Security.Principal.WindowsImpersonationContext impersonationContext; 
     impersonationContext = 
      ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate(); 

     //Insert your code that runs under the security context of the authenticating user here. 

     string script = "C:\\inetpub\\wwwroot\\VRS\\Admins\\PSScripts\\AMMaintMode.vbs"; 
     string mode = "/maint:0"; 
     string serv = "/server:" + servers; 
     string ccserv = "/ccserver:calntmgt501"; 
     using (
     RunspacePool runspace = RunspaceFactory.CreateRunspacePool()) 
     { 
      // open it 
      runspace.Open(); 

      // create a pipeline and feed it the script text 
      PowerShell pipeline = PowerShell.Create(); 

      pipeline.RunspacePool = runspace; 
      pipeline.AddCommand("cscript"); 
      pipeline.AddArgument(script); 
      pipeline.AddArgument(mode); 
      pipeline.AddArgument(serv); 
      pipeline.AddArgument(ccserv); 

      // execute the script 
      IAsyncResult pipeResults = pipeline.BeginInvoke(); 
      PSDataCollection<PSObject> pipeOutput = pipeline.EndInvoke(pipeResults); 

      //pipeline.Invoke(); 
      for (int i = 0; i < pipeOutput.Count; i++) 
      { 
       txtOutput.Text += pipeOutput[i].BaseObject.ToString(); 
       txtOutput.Text += Environment.NewLine; 
      } 

      runspace.Close(); 
     } 

     impersonationContext.Undo(); 

     txtServers.Text = ""; 
    } 

出力結果は以下のとおりです。

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.

AppManager Maintenance Mode CLI V2.1

Connecting to Control Center... Server calntmgt501\NQCCDB via Windows Authentication * Failed to connect to server. Verify credentials. Error: * Login failed for user 'BLACKROCK\USPMVVMT001$'.

+0

実行中のAPPプールとは何ですか? –

+0

遅れて申し訳ありません。 BLACKROCK \ USPMVVMT001 $は、組み込みのシステムアカウントです。 – Jay

+0

アプリケーションプールIDはコードを実行するアカウントです。だから、なぜあなたはそれを実行するユーザーが実行されていないと言うのですか? –

答えて

0

ウェブサイトはWindows認証は、具体的にKerberosを使用している場合は、委任を有効にする必要があります。これは「ダブルホップ」問題として知られています。具体的には、制約付きの委任を有効にするにはドメイン管理者が必要です。 「制約された」部分は、Webサーバが接続する必要があるサービスだけに委任を制限したいということです。

そうしないと、ドメイン管理者があなたのWebサイトにアクセスするだけで、必要な作業を行うことができます。それは大きなセキュリティ上の問題になるでしょう。

関連する問題