public static CimSession Create(string computerName, CimSessionOptions sessionOptions) { IPAddress pAddress = null; InstanceHandle instanceHandle = null; SessionHandle sessionHandle = null; CimSession cimSession; string protocol; DestinationOptionsHandle destinationOptionsHandle; string str = computerName; if (!string.IsNullOrEmpty(str) && IPAddress.TryParse(str, out pAddress) && pAddress.AddressFamily == AddressFamily.InterNetworkV6 && str[0] != '[') { str = string.Concat("[", str, "]"); } IDisposable disposable = CimApplication.AssertNoPendingShutdown(); using (disposable) { ApplicationHandle handle = CimApplication.Handle; if (sessionOptions == null) { protocol = null; } else { protocol = sessionOptions.Protocol; } string str1 = str; if (sessionOptions == null) { destinationOptionsHandle = null; } else { destinationOptionsHandle = sessionOptions.DestinationOptionsHandle ?? sessionOptions.DestinationOptionsHandleOnDemand; } MiResult miResult = ApplicationMethods.NewSession(handle, protocol, str1, destinationOptionsHandle, out instanceHandle, out sessionHandle); if (miResult != MiResult.NOT_FOUND) { CimException.ThrowIfMiResultFailure(miResult, instanceHandle); CimSession cimSession1 = new CimSession(sessionHandle, computerName); cimSession = cimSession1; } else { throw new CimException(miResult, null, instanceHandle, System.Management.Automation.Strings.UnrecognizedProtocolName); } } return cimSession; }
public void Close() { lock (this._disposeThreadSafetyLock) { if (!this._disposed) { this._disposed = true; } else { return; } } MiResult miResult = this._handle.ReleaseHandleSynchronously(); CimException.ThrowIfMiResultFailure(miResult); }
/// <summary> /// Instantiates an empty <see cref="CimInstance"/>. /// </summary> /// <param name="cimClass"></param> /// <exception cref="ArgumentException">Thrown when <paramref name="cimClass"/> is null or when it doesn't follow the format specified by DSP0004</exception> public CimInstance(CimClass cimClass) { if (cimClass == null) { throw new ArgumentNullException("cimClass"); } MI_Instance tmpHandle; MI_Result result = CimApplication.Handle.NewInstanceFromClass(cimClass.CimSystemProperties.ClassName, cimClass.ClassHandle, out tmpHandle); if (result == MI_Result.MI_RESULT_INVALID_PARAMETER) { throw new ArgumentOutOfRangeException("cimClass"); } CimException.ThrowIfMiResultFailure(result); result = tmpHandle.SetNameSpace(cimClass.CimSystemProperties.Namespace); CimException.ThrowIfMiResultFailure(result); result = tmpHandle.SetServerName(cimClass.CimSystemProperties.ServerName); CimException.ThrowIfMiResultFailure(result); this.nativeInstance = tmpHandle; }