private void CreateWmiDataProviderFromWmiItem(wmi_item wmiItem) { if (this.WmiDataProvider == null) { var wmiNamespace = String.Format(@"{0}\{1}", this.TargetInfo.GetAddress(), [email protected]); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); this.WmiDataProvider = new WmiDataProvider(wmiManagementScope); } }
private WmiDataProvider GetWmiDataProvider(string @namespace) { if (this.WmiDataProvider != null) { return(this.WmiDataProvider); } var wmiNamespace = String.Format(@"\\{0}\{1}", this.TargetInfo.GetAddress(), @namespace); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); return(new WmiDataProvider(wmiManagementScope)); }
/// <summary> /// It tries to establish a connection to Windows system through WMI /// </summary> /// <param name="targetIpOrHostname">The IP or hostname of target system.</param> /// <param name="username">A user with administrative privileges.</param> /// <param name="password">User password.</param> /// <returns>True if the connection was established, otherwise False</returns> public virtual Boolean IsTargetWindowsSystem(string targetAddress, string username, string password) { var @namespace = String.Format(@"\\{0}\root\cimv2", targetAddress); var connectionOptions = WmiDataProviderFactory.CreateConnectionOptions(username, password); var connectionScope = new ManagementScope(@namespace, connectionOptions); try { connectionScope.Connect(); return(true); } catch (Exception) { return(false); } }