public ConnectionOptions(string locale, string username, string password, string authority, ImpersonationLevel impersonation, AuthenticationLevel authentication, bool enablePrivileges, ManagementNamedValueCollection context, TimeSpan timeout) : base(context, timeout) { if (locale != null) { this.locale = locale; } this.username = username; this.enablePrivileges = enablePrivileges; if (password != null) { this.securePassword = new SecureString(); for (int i = 0; i < password.Length; i++) { this.securePassword.AppendChar(password[i]); } } if (authority != null) { this.authority = authority; } if (impersonation != ImpersonationLevel.Default) { this.impersonation = impersonation; } if (authentication != AuthenticationLevel.Default) { this.authentication = authentication; } }
/// <summary> /// Constructor por defecto /// </summary> public WmiQueryInput() : base() { DesignBackColor = Color.DeepPink; Impersonation = ImpersonationLevel.Default; EnablePrivileges = true; Scope = @"\\.\root\CIMV2"; }
public NTCreateAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode) { Reserved = ByteReader.ReadByte(this.SMBParameters, 4); NameLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 5); Flags = (NTCreateFlags)LittleEndianConverter.ToUInt32(this.SMBParameters, 7); RootDirectoryFID = LittleEndianConverter.ToUInt32(this.SMBParameters, 11); DesiredAccess = (FileAccessMask)LittleEndianConverter.ToUInt32(this.SMBParameters, 15); AllocationSize = LittleEndianConverter.ToInt64(this.SMBParameters, 19); ExtFileAttributes = (ExtendedFileAttributes)LittleEndianConverter.ToUInt32(this.SMBParameters, 27); ShareAccess = (ShareAccess)LittleEndianConverter.ToUInt32(this.SMBParameters, 31); CreateDisposition = (CreateDisposition)LittleEndianConverter.ToUInt32(this.SMBParameters, 35); CreateOptions = (CreateOptions)LittleEndianConverter.ToUInt32(this.SMBParameters, 39); ImpersonationLevel = (ImpersonationLevel)LittleEndianConverter.ToUInt32(this.SMBParameters, 43); SecurityFlags = (SecurityFlags)ByteReader.ReadByte(this.SMBParameters, 47); int dataOffset = 0; if (isUnicode) { // A Unicode string MUST be aligned to a 16-bit boundary with respect to the beginning of the SMB Header. // Note: SMBData starts at an odd offset. dataOffset = 1; } FileName = SMB1Helper.ReadSMBString(this.SMBData, dataOffset, isUnicode); }
public unsafe SECURITY_QUALITY_OF_SERVICE(ImpersonationLevel impersonationLevel, ContextTrackingMode contextTrackingMode, bool effectiveOnly) { Length = (uint)sizeof(SECURITY_QUALITY_OF_SERVICE); ImpersonationLevel = impersonationLevel; ContextTrackingMode = contextTrackingMode; EffectiveOnly = effectiveOnly ? BOOLEAN.TRUE : BOOLEAN.FALSE; }
//parameterized /// <summary> /// <para>Constructs a new options object to be used for a WMI /// connection with the specified values.</para> /// </summary> /// <param name='locale'>Indicates the locale to be used for this connection</param> /// <param name=' username'>Specifies the user name to be used for the connection. If null the currently logged on user's credentials are used.</param> /// <param name=' password'>Specifies the password for the given username. If null the currently logged on user's credentials are used.</param> /// <param name=' authority'><para>The authority to be used to authenticate the specified user</para></param> /// <param name=' impersonation'>The DCOM impersonation level to be used for this connection</param> /// <param name=' authentication'>The DCOM authentication level to be used for this connection</param> /// <param name=' enablePrivileges'>Specifies whether to enable special user privileges. This should only be used when performing an operation that requires special NT user privileges.</param> /// <param name=' context'>A provider-specific named value pairs object to be passed through to the provider.</param> /// <param name=' timeout'>Reserved for future use.</param> public ConnectionOptions(string locale, string username, string password, string authority, ImpersonationLevel impersonation, AuthenticationLevel authentication, bool enablePrivileges, ManagementNamedValueCollection context, TimeSpan timeout) : base(context, timeout) { if (locale != null) { this.locale = locale; } this.username = username; this.enablePrivileges = enablePrivileges; this.password = new EncryptedData(password); if (authority != null) { this.authority = authority; } if (impersonation != 0) { this.impersonation = impersonation; } if (authentication != 0) { this.authentication = authentication; } }
public static ManagementClass GetClass(string nameSpace, string className, NetworkCredential credential = null, ImpersonationLevel impersonationLevel = ImpersonationLevel.Impersonate, AuthenticationLevel authenticationLevel = AuthenticationLevel.Default) { try { var options = new ConnectionOptions { Impersonation = impersonationLevel, Authentication = authenticationLevel, Username = credential?.UserName, Password = credential?.Password, SecurePassword = credential?.SecurePassword, EnablePrivileges = true }; var scope = new ManagementScope(nameSpace, options); scope.Connect(); var option = new ObjectGetOptions(null, TimeSpan.MaxValue, true); var path = new ManagementPath(className); var cls = new ManagementClass(scope, path, option); return(cls); } catch (Exception ex) { } return(null); }
public ConnectionOptions(string locale, string username, SecureString password, string authority, ImpersonationLevel impersonation, AuthenticationLevel authentication, bool enablePrivileges, ManagementNamedValueCollection context, TimeSpan timeout) : base(context, timeout) { if (locale != null) { this.locale = locale; } this.username = username; this.enablePrivileges = enablePrivileges; if (password != null) { this.securePassword = password.Copy(); } if (authority != null) { this.authority = authority; } if (impersonation != ImpersonationLevel.Default) { this.impersonation = impersonation; } if (authentication != AuthenticationLevel.Default) { this.authentication = authentication; } }
public NTTransactCreateRequest(byte[] parameters, byte[] data, bool isUnicode) { int parametersOffset = 0; Flags = (NTCreateFlags)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); RootDirectoryFID = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); DesiredAccess = (AccessMask)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); AllocationSize = LittleEndianReader.ReadInt64(parameters, ref parametersOffset); ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); ShareAccess = (ShareAccess)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); CreateDisposition = (CreateDisposition)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); CreateOptions = (CreateOptions)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); uint securityDescriptiorLength = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); _ = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); uint nameLength = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); ImpersonationLevel = (ImpersonationLevel)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset); SecurityFlags = (SecurityFlags)ByteReader.ReadByte(parameters, ref parametersOffset); if (isUnicode) { parametersOffset++; } Name = SMB1Helper.ReadFixedLengthString(parameters, ref parametersOffset, isUnicode, (int)nameLength); if (securityDescriptiorLength > 0) { SecurityDescriptor = new SecurityDescriptor(data, 0); } ExtendedAttributes = FileFullEAInformation.ReadList(data, (int)securityDescriptiorLength); }
/// <summary> /// Initialises a new instance of <see cref="Impersonation"/>. /// </summary> /// <param name="domain">The domain of the target user.</param> /// <param name="username">The target user to impersonate.</param> /// <param name="password">The target password of the user to impersonate.</param> /// <param name="level">The security level of this impersonation.</param> public Impersonation(string domain, string username, string password, ImpersonationLevel level) { this.domain = domain; this.username = username; this.password = password; this.level = level; Logon(); }
public WMIManager() { string computerName = "."; WMIPath = String.Format(@"\\{0}\ROOT\CIMV2", computerName); UserName = ""; Password = ""; ImpersonationLevel = ImpersonationLevel.Impersonate; }
/// <summary> /// Sets the local authentication information that will be used to make calls on the specified proxy. /// </summary> /// <param name="this">The <see cref="WmiLight.Wbem.IWbemServices"/> object which will by wrapped with a proxy.</param> /// <param name="impersonationLevel">The impersonation level which will be used.</param> /// <param name="authenticationLevel">The authentication level which will be used.</param> #endregion internal static void SetProxy(this IWbemServices @this, ImpersonationLevel impersonationLevel, AuthenticationLevel authenticationLevel) { HResult hr = NativeMethods.CoSetProxyBlanketForIWbemServices.Invoke(@this, null, null, null, impersonationLevel, authenticationLevel); if (hr.Failed) { throw (Exception)hr; } }
/// <summary> /// Constructor por defecto /// </summary> public WmiProcessExecutionInput() : base() { DesignBackColor = Color.DeepPink; Impersonation = ImpersonationLevel.Default; EnablePrivileges = true; Host = "."; ShowWindowMode = EView.SW_HIDE; Timeout = TimeSpan.FromSeconds(30); }
public NativeToken Duplicate(ImpersonationLevel impersonation) { var success = DuplicateToken(tokenHandle, impersonation, out var newToken); if (!success) { throw new Win32Exception(); } return(new NativeToken(newToken)); }
/// <summary> /// Add Connection driver to use DCom connection /// </summary> /// <param name="optionsBuilder">WmiContextOptionsBuilder to extend</param> /// <param name="computerName">Computer name or IP address to connect</param> /// <param name="nameSpace">WMI Namespace to work with</param> /// <param name="impersonationLevel">Impersonation level</param> /// <param name="domain">User domain</param> /// <param name="userName">User name</param> /// <param name="password">User password</param> /// <returns></returns> public static WmiContextOptionsBuilder UseDCom( this WmiContextOptionsBuilder optionsBuilder, string computerName, string nameSpace, string domain, string userName, string password, ImpersonationLevel impersonationLevel = ImpersonationLevel.Impersonate) { optionsBuilder.Options.Connection = new DComConnection( computerName, nameSpace, domain, userName, password, impersonationLevel); return(optionsBuilder); }
public ConnectionOptions (string locale, string username, string password, string authority, ImpersonationLevel impersonation, AuthenticationLevel authentication, bool enablePrivileges, ManagementNamedValueCollection context, TimeSpan timeout) { }
public ConnectionOptions(string locale, string username, SecureString password, string authority, ImpersonationLevel impersonation, AuthenticationLevel authentication, bool enablePrivileges, ManagementNamedValueCollection context, TimeSpan timeout) { }
/// <summary> /// Initialises a new instance of <see cref="Impersonation" />. /// </summary> /// <param name="domain">The domain of the target user.</param> /// <param name="username">The target user to impersonate.</param> /// <param name="password">The target password of the user to impersonate.</param> /// <param name="level">The security level of this impersonation.</param> public Impersonation(string domain, string username, string password, ImpersonationLevel level) { _domain = domain; _username = username; _password = password; _level = level; _logonProvider = LogonProvider.WinNT50; _logonType = LogonType.NewCredentials; Logon(); }
public StopComputerCommand() { this._asjob = false; this._authentication = AuthenticationLevel.Packet; string[] strArrays = new string[1]; strArrays[0] = "."; this._computername = strArrays; this._impersonation = ImpersonationLevel.Impersonate; this._throttlelimit = 32; this._force = false; }
public WmiBaseCmdlet() { string[] strArrays = new string[1]; strArrays[0] = "localhost"; this.computerName = strArrays; this.nameSpace = "root\\cimv2"; this.impersonationLevel = ImpersonationLevel.Impersonate; this.authenticationLevel = AuthenticationLevel.Packet; this.async = false; this.throttleLimit = WmiBaseCmdlet.DEFAULT_THROTTLE_LIMIT; this._context = LocalPipeline.GetExecutionContextFromTLS(); }
public TestConnectionCommand() { this.asjob = false; this.authentication = AuthenticationLevel.Packet; this.buffersize = 32; this.count = 4; string[] strArrays = new string[1]; strArrays[0] = "."; this.source = strArrays; this.impersonation = ImpersonationLevel.Impersonate; this.throttlelimit = 32; this.timetolive = 80; this.delay = 1; this.quietResults = new Dictionary <string, bool>(); }
/// <summary> /// Initialises a new instance of <see cref="Impersonation" />. /// </summary> /// <param name="domain">The domain of the target user.</param> /// <param name="username">The target user to impersonate.</param> /// <param name="password">The target password of the user to impersonate.</param> /// <param name="level">The security level of this impersonation.</param> /// <param name="logontype">The logontype.</param> /// <param name="logonProvider">The logon provider.</param> public Impersonation(string domain, string username, string password, ImpersonationLevel level, LogonType logontype, LogonProvider logonProvider) { _domain = domain; _username = username; _password = password; _level = level; _logonProvider = logonProvider; _logonType = logontype; Logon(); }
public CreateRequest(byte[] buffer, int offset) : base(buffer, offset) { StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0); SecurityFlags = ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 2); RequestedOplockLevel = (OplockLevel)ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 3); ImpersonationLevel = (ImpersonationLevel)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4); SmbCreateFlags = LittleEndianConverter.ToUInt64(buffer, offset + SMB2Header.Length + 8); Reserved = LittleEndianConverter.ToUInt64(buffer, offset + SMB2Header.Length + 16); DesiredAccess = new AccessMask(buffer, offset + SMB2Header.Length + 24); FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 28); ShareAccess = (ShareAccess)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 32); CreateDisposition = (CreateDisposition)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 36); CreateOptions = (CreateOptions)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 40); NameOffset = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 44); NameLength = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 46); CreateContextsOffsets = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 48); CreateContextsLength = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 52); Name = ByteReader.ReadUTF16String(buffer, offset + NameOffset, NameLength / 2); if (CreateContextsLength > 0) { CreateContexts = CreateContext.ReadCreateContextList(buffer, (int)CreateContextsOffsets); } }
public NTCreateAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode) { Reserved = ByteReader.ReadByte(this.SMBParameters, 4); ushort nameLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 5); Flags = (NTCreateFlags)LittleEndianConverter.ToUInt32(this.SMBParameters, 7); RootDirectoryFID = LittleEndianConverter.ToUInt32(this.SMBParameters, 11); DesiredAccess = (DesiredAccess)LittleEndianConverter.ToUInt32(this.SMBParameters, 15); AllocationSize = LittleEndianConverter.ToUInt64(this.SMBParameters, 19); ExtFileAttributes = (ExtendedFileAttributes)LittleEndianConverter.ToUInt32(this.SMBParameters, 27); ShareAccess = (ShareAccess)LittleEndianConverter.ToUInt32(this.SMBParameters, 31); CreateDisposition = (CreateDisposition)LittleEndianConverter.ToUInt32(this.SMBParameters, 35); CreateOptions = (CreateOptions)LittleEndianConverter.ToUInt32(this.SMBParameters, 39); ImpersonationLevel = (ImpersonationLevel)LittleEndianConverter.ToUInt32(this.SMBParameters, 43); SecurityFlags = (SecurityFlags)ByteReader.ReadByte(this.SMBParameters, 47); int dataOffset = 0; if (isUnicode) { dataOffset = 1; // 1 byte padding for 2 byte alignment } FileName = SMBHelper.ReadSMBString(this.SMBData, dataOffset, isUnicode); }
/// <summary> /// Sets the authentication information that will be used to make calls on the specified proxy. /// </summary> /// <param name="this">The <see cref="WmiLight.Wbem.IWbemServices"/> object which will by wrapped with a proxy.</param> /// <param name="userName">The name of the user.</param> /// <param name="password">The password of the user.</param> /// <param name="authority"> /// The authority to be used to authenticate the specified user. /// <para /> /// Example: "ntlmdomain:MYDOMAIN" /// </param> /// <param name="impersonationLevel">The impersonation level which will be used.</param> /// <param name="authenticationLevel">The authentication level which will be used.</param> #endregion internal static void SetProxy(this IWbemServices @this, string userName, string password, string authority, ImpersonationLevel impersonationLevel, AuthenticationLevel authenticationLevel) { HResult hr = NativeMethods.CoSetProxyBlanketForIWbemServices.Invoke(@this, userName, password, authority, impersonationLevel, authenticationLevel); if (hr.Failed) { throw (Exception)hr; } }
/// <summary> /// Get the Connection Options /// </summary> /// <param name="Authentication"></param> /// <param name="Impersonation"></param> /// <param name="Credential"></param> /// <returns></returns> internal static ConnectionOptions GetConnectionOptions(AuthenticationLevel Authentication, ImpersonationLevel Impersonation, PSCredential Credential) { ConnectionOptions options = new ConnectionOptions(); options.Authentication = Authentication; options.EnablePrivileges = true; options.Impersonation = Impersonation; if (Credential != null) { options.Username = Credential.UserName; options.SecurePassword = Credential.Password; } return options; }
internal static ConnectionOptions GetConnection(AuthenticationLevel Authentication, ImpersonationLevel Impersonation, PSCredential Credential) { ConnectionOptions connectionOption = new ConnectionOptions(); connectionOption.Authentication = Authentication; connectionOption.EnablePrivileges = true; connectionOption.Impersonation = Impersonation; if (Credential != null) { connectionOption.Username = Credential.UserName; //connectionOption.SecurePassword = Credential.Password; } return connectionOption; }
public RestartComputerCommand() { this._asjob = false; this._dcomAuthentication = AuthenticationLevel.Packet; this._impersonation = ImpersonationLevel.Impersonate; this._protocol = "DCOM"; string[] strArrays = new string[1]; strArrays[0] = "."; this._computername = strArrays; this._validatedComputerNames = new List<string>(); this._waitOnComputers = new List<string>(); this._uniqueComputerNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase); this._throttlelimit = 32; this._timeout = -1; this._waitFor = WaitForServiceTypes.PowerShell; this._delay = 5; string[] strArrays1 = new string[4]; strArrays1[0] = "|"; strArrays1[1] = "/"; strArrays1[2] = "-"; strArrays1[3] = "\\"; this._indicator = strArrays1; this._cancel = new CancellationTokenSource(); this._waitHandler = new ManualResetEventSlim(false); this._computerInfos = new Dictionary<string, RestartComputerCommand.ComputerInfo>(StringComparer.OrdinalIgnoreCase); this._shortLocalMachineName = Dns.GetHostName(); this._fullLocalMachineName = Dns.GetHostEntry("").HostName; }
internal static ConnectionOptions GetConnection(AuthenticationLevel Authentication, ImpersonationLevel Impersonation, PSCredential Credential) { ConnectionOptions connectionOption = new ConnectionOptions(); connectionOption.Authentication = Authentication; connectionOption.EnablePrivileges = true; connectionOption.Impersonation = Impersonation; if (Credential != null) { connectionOption.Username = Credential.UserName; //connectionOption.SecurePassword = Credential.Password; } return(connectionOption); }
public static extern bool DuplicateToken( IntPtr hToken, ImpersonationLevel impersonationLevel, out IntPtr phNewToken);
public TestConnectionCommand() { this.asjob = false; this.authentication = AuthenticationLevel.Packet; this.buffersize = 32; this.count = 4; string[] strArrays = new string[1]; strArrays[0] = "."; this.source = strArrays; this.impersonation = ImpersonationLevel.Impersonate; this.throttlelimit = 32; this.timetolive = 80; this.delay = 1; this.quietResults = new Dictionary<string, bool>(); }
public static extern int DuplicateToken(IntPtr hToken, ImpersonationLevel impersonationLevel, ref IntPtr hNewToken);
internal static extern bool DuplicateToken(SafeTokenHandle currentToken, ImpersonationLevel impersonation, out SafeTokenHandle newToken);
private void InitializeFlags(ConnectionInfo connectionInfo, SecurityContextMode securityContextMode) { string sspi = connectionInfo.Sspi; ImpersonationLevel impersonationLevel = connectionInfo.ImpersonationLevel; if (this.m_isSchannel) { switch (securityContextMode) { case SecurityContextMode.block: this.CheckIfCapabilityIsSupported(sspi, PackageCapabilities.Connection); this.m_RequestedFlags = ContextFlags.Connection; break; case SecurityContextMode.stream: this.CheckIfCapabilityIsSupported(sspi, PackageCapabilities.Stream); this.m_RequestedFlags = ContextFlags.Stream; break; default: throw new AdomdConnectionException("Unsupported TLS mode " + securityContextMode.ToString(), null, ConnectionExceptionCause.AuthenticationFailed); } switch (impersonationLevel) { case ImpersonationLevel.Anonymous: case ImpersonationLevel.Identify: case ImpersonationLevel.Impersonate: switch (connectionInfo.ProtectionLevel) { case ProtectionLevel.None: case ProtectionLevel.Connection: case ProtectionLevel.Integrity: throw new AdomdConnectionException(XmlaSR.Authentication_Sspi_SchannelSupportsOnlyPrivacyLevel, null, ConnectionExceptionCause.AuthenticationFailed); case ProtectionLevel.Privacy: this.m_RequestedFlags |= (ContextFlags.ReplayDetect | ContextFlags.SequenceDetect | ContextFlags.Confidentiality | ContextFlags.UseSuppliedCreds | ContextFlags.Integrity); return; default: throw new AdomdConnectionException(XmlaSR.Authentication_Sspi_SchannelUnsupportedProtectionLevel, null, ConnectionExceptionCause.AuthenticationFailed); } case ImpersonationLevel.Delegate: throw new AdomdConnectionException(XmlaSR.Authentication_Sspi_SchannelCantDelegate, null, ConnectionExceptionCause.AuthenticationFailed); default: throw new AdomdConnectionException(XmlaSR.Authentication_Sspi_SchannelUnsupportedImpersonationLevel, null, ConnectionExceptionCause.AuthenticationFailed); } } else { this.m_RequestedFlags = (ContextFlags.MutualAuth | ContextFlags.Connection); switch (impersonationLevel) { case ImpersonationLevel.Identify: this.m_RequestedFlags |= ContextFlags.Identify; break; case ImpersonationLevel.Impersonate: this.CheckIfCapabilityIsSupported(sspi, PackageCapabilities.Impersonation); break; case ImpersonationLevel.Delegate: this.m_RequestedFlags |= ContextFlags.Delegate; break; } switch (connectionInfo.ProtectionLevel) { case ProtectionLevel.Connection: this.m_RequestedFlags |= ContextFlags.NoIntegrity; return; case ProtectionLevel.Integrity: this.CheckIfCapabilityIsSupported(sspi, PackageCapabilities.Integrity); this.m_RequestedFlags |= (ContextFlags.ReplayDetect | ContextFlags.SequenceDetect | ContextFlags.Integrity); return; case ProtectionLevel.Privacy: this.CheckIfCapabilityIsSupported(sspi, PackageCapabilities.Privacy); this.m_RequestedFlags |= (ContextFlags.ReplayDetect | ContextFlags.SequenceDetect | ContextFlags.Confidentiality | ContextFlags.Integrity); return; default: return; } } }
/// <summary> /// Constructor that configures connection to host using specified credentials and takes WMI namespace /// </summary> /// <param name="computerName">Computer name or IP address to connect</param> /// <param name="nameSpace">Namespace to configure</param> /// <param name="impersonationLevel">Impersonation Level</param> /// <param name="domain">User domain</param> /// <param name="userName">User name</param> /// <param name="password">User password</param> public DComConnection(string computerName, string nameSpace, string domain, string userName, string password, ImpersonationLevel impersonationLevel = ImpersonationLevel.Impersonate) => CreateDComConnection(computerName, nameSpace, new ConnectionOptions
public static extern bool DuplicateTokenEx(IntPtr existingToken, uint desiredAccess, IntPtr tokenAttributes, ImpersonationLevel level, TokenType type, out IntPtr newToken);
/// <summary> /// Sets the authentication information and executes a query to retrieve objects. /// </summary> /// <param name="this">The <see cref="WmiLight.Wbem.IWbemServices"/> object which will by wrapped with a proxy.</param> /// <param name="query">The query which will be executed.</param> /// <param name="enumeratorBehaviorOption">Flag for the behavior of the created enumerator.</param> /// <param name="ctx"> /// Typically, this is NULL. /// Otherwise, this is an <see cref="WmiLight.Wbem.IWbemContext"/> object required by one or more dynamic class providers. /// </param> /// <param name="impersonationLevel">The impersonation level which will be used.</param> /// <param name="authenticationLevel">The authentication level which will be used.</param> /// <param name="userName">The name of the user.</param> /// <param name="password">The password of the user.</param> /// <param name="authority"> /// The authority to be used to authenticate the specified user. /// <para /> /// Example: "ntlmdomain:MYDOMAIN" /// </param> /// <returns>The enumerator for the results of the query.</returns> #endregion internal static IWbemClassObjectEnumerator ExecQuery(this IWbemServices @this, string query, WbemClassObjectEnumeratorBehaviorOption enumeratorBehaviorOption, IWbemContext ctx, AuthenticationLevel impersonationLevel, ImpersonationLevel authenticationLevel, string userName, string password, string authority) { IWbemClassObjectEnumerator enumerator; HResult hr = NativeMethods.ExecQueryWmi("WQL", query, enumeratorBehaviorOption, ctx, out enumerator, impersonationLevel, authenticationLevel, @this, userName, password, authority); if (hr.Failed) { throw (Exception)hr; } return(enumerator); }
public ImpersonationHelper(LogonProvider logonProvider, ImpersonationLevel level, LogonTypes logonType) { this._logonProvider = logonProvider; this._impersonationLevel = level; this._logonType = logonType; }
public ImpersonationHelper(LogonProvider logonProvider, ImpersonationLevel level) : this (logonProvider, level, LogonTypes.LOGON32_LOGON_NETWORK) {}
//parameterized /// <summary> /// <para> Initializes a new instance of the <see cref='System.Management.ConnectionOptions'/> class to be used for a WMI /// connection, using the specified values.</para> /// </summary> /// <param name='locale'>The locale to be used for the connection.</param> /// <param name=' username'>The user name to be used for the connection. If null, the credentials of the currently logged-on user are used.</param> /// <param name=' securepassword'>The secure password for the given user name. If the user name is also null, the credentials used will be those of the currently logged-on user.</param> /// <param name=' authority'><para>The authority to be used to authenticate the specified user.</para></param> /// <param name=' impersonation'>The COM impersonation level to be used for the connection.</param> /// <param name=' authentication'>The COM authentication level to be used for the connection.</param> /// <param name=' enablePrivileges'><see langword='true'/>to enable special user privileges; otherwise, <see langword='false'/> . This parameter should only be used when performing an operation that requires special Windows NT user privileges.</param> /// <param name=' context'>A provider-specific, named value pairs object to be passed through to the provider.</param> /// <param name=' timeout'>Reserved for future use.</param> public ConnectionOptions (string locale, string username, SecureString password, string authority, ImpersonationLevel impersonation, AuthenticationLevel authentication, bool enablePrivileges, ManagementNamedValueCollection context, TimeSpan timeout) : base (context, timeout) { if (locale != null) this.locale = locale; this.username = username; this.enablePrivileges = enablePrivileges; if (password != null) { this.securePassword = password.Copy(); } if (authority != null) this.authority = authority; if (impersonation != 0) this.impersonation = impersonation; if (authentication != 0) this.authentication = authentication; }