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$'.
実行中のAPPプールとは何ですか? –
遅れて申し訳ありません。 BLACKROCK \ USPMVVMT001 $は、組み込みのシステムアカウントです。 – Jay
アプリケーションプールIDはコードを実行するアカウントです。だから、なぜあなたはそれを実行するユーザーが実行されていないと言うのですか? –