如何使用模拟ImpersonationLevel启动PowerShell进程?

时间:2018-05-11 13:16:49

标签: c# powershell security com impersonation

我必须将RPC_C_IMP_LEVEL_IMPERSONATE设置为powershell进程。你知道我怎么能做到这一点吗?

我只找到this信息。它是关于通过CoInitializeSecurity使用C ++更改默认模拟级别。但遗憾的是,我无法将其用于powershell。它需要main函数。

/// <summary>
/// The main entry point for the application.
/// Do not set STAThread since CoInitializeSecurity is called 
/// with to high security automatically (and it can only be called once).
/// </summary>
//[STAThread]
static void Main() 
{
    // Set threading apartment
    System.Threading.Thread.CurrentThread.ApartmentState = ApartmentState.STA; 
    CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,
        IntPtr.Zero,RpcAuthnLevel.None ,
        RpcImpLevel.Impersonate,IntPtr.Zero, EoAuthnCap.None, IntPtr.Zero ); 

    Application.MainForm = new MainForm();
    System.Windows.Forms.Application.Run(Application.MainForm);
}

我有一个客户端(powershell)和服务。我不能打电话给服务,因为它给了我以下错误:

Either a required impersonation level was not provided, or the provided impersonation level is invalid.

我在*.log中发现当前的假冒等级为Identification

0 个答案:

没有答案
相关问题