using System; using System.Runtime.InteropServices; using System.Reflection; namespace Microsoft.VirtualServer.Interop { using System; using System.Runtime.InteropServices; using System.Reflection; public class Powershell { const uint EOAC_NONE = 0; const uint RPC_C_AUTHN_WINNT = 10; const uint RPC_C_AUTHZ_NONE = 0; const uint RPC_C_AUTHN_LEVEL_DEFAULT = 0; const uint RPC_C_IMP_LEVEL_IMPERSONATE = 3; [DllImport( "Ole32.dll", CharSet = CharSet.Auto ) ] public static extern int CoSetProxyBlanket( IntPtr pProxy, uint dwAuthnSvc, uint dwAuthzSvc, uint pServerPrincName, uint dwAuthLevel, uint dwImpLevel, IntPtr pAuthInfo, uint dwCapabilities ); public static int SetSecurity( object objDCOM ) { IntPtr dispatchInterface = Marshal.GetIDispatchForObject(objDCOM); int hr = CoSetProxyBlanket( dispatchInterface, //pProxy RPC_C_AUTHN_WINNT, //dwAuthnSvc RPC_C_AUTHZ_NONE, //dwAuthzSvc 0, //pServerPrincName RPC_C_AUTHN_LEVEL_DEFAULT, //dwAuthnLevel RPC_C_IMP_LEVEL_IMPERSONATE, //dwImpLevel IntPtr.Zero, //pAuthInfo EOAC_NONE //dwCapabilities ); return hr; } } }