2011-07-21 15 views
6

PowerShellとC#で偽装を実行する際に幾分奇妙なエラーが発生します。フォローコードを実行してもエラーは表示されません。上記のC#コードは、ローカルで正常に動作しますPowershellでWindowsIdentityで偽装するとFileNotFoundExceptionがスローされる

$info = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer 
     ; $info.ConvertToDateTime($info.LastBootUpTime) 

CmdletMap[PSVocab.OsBootTime]ためのPSスクリプトは単純である

PSObject result = null; 
using (PowerShell powershell = PowerShell.Create()) 
{ 
    RunspaceConfiguration config = RunspaceConfiguration.Create(); 
    powershell.Runspace = RunspaceFactory.CreateRunspace(config); 
    powershell.Runspace.Open(); 
    powershell.AddScript(String.Format(CmdletMap[PSVocab.OsBootTime], 
         this.ComputerName)); 
    result = powershell.Invoke().First(); 
    powershell.Runspace.Close(); 
} 

return DateTime.Parse(result.ToString()); 

FileNotFoundException: C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll 

とデバッグが、それはRunspaceConfiguration.Create()で失敗したことを示しています

WindowsIdentity ImpersonatedIdentity = new WindowsIdentity(ImpersonateUserName); 
WindowsImpersonationContext impersonatedContext 
    = ImpersonatedIdentity.Impersonate(); 
try 
{ 
PSObject result = null; 
using (PowerShell powershell = PowerShell.Create()) 
{ 
    RunspaceConfiguration config = RunspaceConfiguration.Create(); 
    powershell.Runspace = RunspaceFactory.CreateRunspace(config); 
    powershell.Runspace.Open(); 
    powershell.AddScript(String.Format(CmdletMap[PSVocab.OsBootTime], 
          this.ComputerName)); 
    result = powershell.Invoke().First(); 
    powershell.Runspace.Close(); 
} 

return DateTime.Parse(result.ToString()); 
} catch (Exception ex) { // do logging here } 

が、私は次の例外を取得:しかし、かつて私はそうのように、Windowsの偽装と同じブロックを持っていました。しかし、なぜか分からない。

しかし、DLLは既にGACに登録されていますが、プロジェクト自体で参照されています。また、パスとバージョンが正しいことを確認しました。取ら

参考文献:

は、誰かがこれに洞察力を与えることができますか?

答えて

0

偽装しようとしているユーザーが、GAC内の必要なPowerShellファイルにアクセスするための十分な権限を持っていない可能性があります。

ユーザーがローカル管理者権限を使って動作しているかどうかを確認します。これは動作し、ローカル管理者権限を取り消し、必要に応じてファイルのアクセス許可を追加します。

関連する問題