public int ExecQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { IEnumerable <IWbemClassObject_DoNotMarshal> list = WMIDatabaseFactory.Get(_currentNamespace, strQuery); ppEnum = new UnixEnumWbemClassObject(list); return(0); }
// IWbemProviderInit int IWbemProviderInit.Initialize_( [In][MarshalAs(UnmanagedType.LPWStr)] string wszUser, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.LPWStr)] string wszNamespace, [In][MarshalAs(UnmanagedType.LPWStr)] string wszLocale, [In][MarshalAs(UnmanagedType.Interface)] IWbemServices pNamespace, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemProviderInitSink pInitSink) { this.pNamespaceNA = pNamespace; RelocateNamespaceRCWToMTA(); this.pSinkNA = null; this.pSinkMTA = null; lock (mapQueryIdToQuery) { mapQueryIdToQuery.Clear(); } pInitSink.SetStatus_((int)tag_WBEM_EXTRA_RETURN_CODES.WBEM_S_INITIALIZED, 0); Marshal.ReleaseComObject(pInitSink); return(0); }
/// <summary> /// <para>Internal method to return an IWbemContext representation /// of the named value collection.</para> /// </summary> internal IWbemContext GetContext() { IWbemContext wbemContext = null; // Only build a context if we have something to put in it if (0 < Count) { int status = (int)ManagementStatus.NoError; try { wbemContext = (IWbemContext) new WbemContext(); foreach (string name in this) { object val = base.BaseGet(name); status = wbemContext.SetValue_(name, 0, ref val); if ((status & 0x80000000) != 0) { break; } } } catch {} // } return(wbemContext); }
public int CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { var items = WMIDatabaseFactory.Get(_currentNamespace, strFilter); ppEnum = new UnixEnumWbemClassObject(items); return(0); }
internal static int CreateClassEnumWmi(string strSuperclass, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { var svc = pCurrentNamespace as UnixWbemServices; var items = WMIDatabaseFactory.Get (svc.CurrentNamespace, "SELECT * FROM " + strSuperclass); ppEnum = new UnixEnumWbemClassObject(items); return 0; }
int IWbemServices_Old.CreateInstanceEnumAsync_([In][MarshalAs(UnmanagedType.BStr)] string strFilter, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { IWbemClassObjectFreeThreaded classObj; pNamespace.GetObject_(strFilter, 0, pCtx, out classObj, IntPtr.Zero); IWbemClassObjectFreeThreaded inst; classObj.SpawnInstance_(0, out inst); foreach (GCHandle h in InstrumentedAssembly.mapIDToRef.Values) { if (h.IsAllocated && h.Target.GetType().Name == strFilter) { Object o = h.GetHashCode(); inst.Put_("InstanceId", 0, ref o, 0); o = Instrumentation.ProcessIdentity; inst.Put_("ProcessId", 0, ref o, 0); ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()]; // func(h.Target, inst); // pResponseHandler.Indicate_(1, ref inst); } } pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return(0); }
int IWbemServices_Old.PutInstanceAsync_([In][MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pInst, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
int IWbemServices_Old.PutInstance_([In][MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pInst, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In] IntPtr ppCallResult) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
int IWbemServices_Old.DeleteInstanceAsync_([In][MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
int IWbemServices_Old.DeleteInstance_([In][MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In] IntPtr ppCallResult) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
internal IWbemContext GetContext() { IWbemContext context = null; if (0 < this.Count) { try { context = (IWbemContext) new WbemContext(); foreach (string str in this) { object pValue = base.BaseGet(str); if ((context.SetValue_(str, 0, ref pValue) & 0x80000000L) != 0L) { return(context); } } return(context); } catch { } } return(context); }
int IWbemServices_Old.CreateClassEnumAsync_([In][MarshalAs(UnmanagedType.BStr)] string strSuperclass, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
// IWbemServices int IWbemServices_Old.OpenNamespace_([In][MarshalAs(UnmanagedType.BStr)] string strNamespace, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][Out][MarshalAs(UnmanagedType.Interface)] ref IWbemServices ppWorkingNamespace, [In] IntPtr ppCallResult) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
internal static int CreateInstanceEnumWmi(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { var svc = pCurrentNamespace as UnixWbemServices; var items = WMIDatabaseFactory.Get(svc.CurrentNamespace, "SELECT * FROM " + strFilter); ppEnum = new UnixEnumWbemClassObject(items); return(0); }
int IWbemServices_Old.CreateInstanceEnum_([In][MarshalAs(UnmanagedType.BStr)] string strFilter, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [Out][MarshalAs(UnmanagedType.Interface)] out IEnumWbemClassObject ppEnum) { ppEnum = null; return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
int IWbemServices_Old.ExecNotificationQueryAsync_([In][MarshalAs(UnmanagedType.BStr)] string strQueryLanguage, [In][MarshalAs(UnmanagedType.BStr)] string strQuery, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
int IWbemServices_Old.GetObject_([In][MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][Out][MarshalAs(UnmanagedType.Interface)] ref IWbemClassObject_DoNotMarshal ppObject, [In] IntPtr ppCallResult) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
int IWbemServices_Old.ExecMethodAsync_([In][MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In][MarshalAs(UnmanagedType.BStr)] string strMethodName, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pInParams, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
internal int CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, ref IEnumWbemClassObject ppEnum) { int num = -2147217407; if (this.scope != null) { num = WmiNetUtilsHelper.CreateInstanceEnumWmi_f(strFilter, lFlags, pCtx, out ppEnum, (int) this.scope.Options.Authentication, (int) this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority); } return num; }
internal int ExecMethod_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObjectFreeThreaded pInParams, ref IWbemClassObjectFreeThreaded ppOutParams, IntPtr ppCallResult) { int num = -2147217407; if (!object.ReferenceEquals(ppCallResult, IntPtr.Zero)) { num = this.pWbemServiecsSecurityHelper.ExecMethod_(strObjectPath, strMethodName, lFlags, pCtx, (IntPtr) pInParams, out ppOutParams, ppCallResult); } return num; }
internal int DeleteInstance_(string strObjectPath, int lFlags, IWbemContext pCtx, IntPtr ppCallResult) { int num = -2147217407; if (!object.ReferenceEquals(ppCallResult, IntPtr.Zero)) { num = this.pWbemServiecsSecurityHelper.DeleteInstance_(strObjectPath, lFlags, pCtx, ppCallResult); } return num; }
int IWbemServices_Old.ExecNotificationQuery_([In][MarshalAs(UnmanagedType.BStr)] string strQueryLanguage, [In][MarshalAs(UnmanagedType.BStr)] string strQuery, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [Out][MarshalAs(UnmanagedType.Interface)] out IEnumWbemClassObject ppEnum) { ppEnum = null; return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED)); }
internal int GetObject_(string strObjectPath, int lFlags, IWbemContext pCtx, ref IWbemClassObjectFreeThreaded ppObject, IntPtr ppCallResult) { int num = -2147217407; if (!object.ReferenceEquals(ppCallResult, IntPtr.Zero)) { num = this.pWbemServiecsSecurityHelper.GetObject_(strObjectPath, lFlags, pCtx, out ppObject, ppCallResult); } return(num); }
internal int PutInstance_(IWbemClassObjectFreeThreaded pInst, int lFlags, IWbemContext pCtx, IntPtr ppCallResult) { int num = -2147217407; if (this.scope != null) { num = WmiNetUtilsHelper.PutInstanceWmi_f((IntPtr)pInst, lFlags, pCtx, ppCallResult, (int)this.scope.Options.Authentication, (int)this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority); } return(num); }
internal int CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, ref IEnumWbemClassObject ppEnum) { int num = -2147217407; if (this.scope != null) { num = WmiNetUtilsHelper.CreateInstanceEnumWmi_f(strFilter, lFlags, pCtx, out ppEnum, (int)this.scope.Options.Authentication, (int)this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority); } return(num); }
internal int DeleteInstance_(string strObjectPath, int lFlags, IWbemContext pCtx, IntPtr ppCallResult) { int num = -2147217407; if (!object.ReferenceEquals(ppCallResult, IntPtr.Zero)) { num = this.pWbemServiecsSecurityHelper.DeleteInstance_(strObjectPath, lFlags, pCtx, ppCallResult); } return(num); }
public int ExecMethod_ (string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IntPtr pInParams, out IWbemClassObjectFreeThreaded ppOutParams, IntPtr ppCallResult) { string strQuery = QueryParser.GetQueryFromPath (strObjectPath); var items = WMIDatabaseFactory.Get (_currentNamespace, strQuery); ppOutParams = null; foreach (var obj in items) { var intPtr = MarshalWbemObject.GetInstance(null).MarshalManagedToNative (obj); ppOutParams = new IWbemClassObjectFreeThreaded(intPtr); } return 0; }
public string GetText(TextFormat format) { int objectText_; string str = null; TextFormat textFormat = format; switch (textFormat) { case TextFormat.Mof: { objectText_ = this.wbemObject.GetObjectText_(0, out str); if (objectText_ < 0) { if (((long)objectText_ & (long)-4096) != (long)-2147217408) { Marshal.ThrowExceptionForHR(objectText_); } else { ManagementException.ThrowWithExtendedInfo((ManagementStatus)objectText_); } } return(str); } case TextFormat.CimDtd20: case TextFormat.WmiDtd20: { IWbemObjectTextSrc wbemObjectTextSrc = (IWbemObjectTextSrc)(new WbemObjectTextSrc()); IWbemContext wbemContext = (IWbemContext)(new WbemContext()); object obj = true; wbemContext.SetValue_("IncludeQualifiers", 0, ref obj); wbemContext.SetValue_("IncludeClassOrigin", 0, ref obj); if (wbemObjectTextSrc != null) { objectText_ = wbemObjectTextSrc.GetText_(0, (IWbemClassObject_DoNotMarshal)Marshal.GetObjectForIUnknown(this.wbemObject), (uint)format, wbemContext, out str); if (objectText_ < 0) { if (((long)objectText_ & (long)-4096) != (long)-2147217408) { Marshal.ThrowExceptionForHR(objectText_); } else { ManagementException.ThrowWithExtendedInfo((ManagementStatus)objectText_); } } } return(str); } } return(null); }
public int GetObject_(string strObjectPath, int lFlags, IWbemContext pCtx, out IWbemClassObjectFreeThreaded ppObject, IntPtr ppCallResult) { if (ppCallResult == IntPtr.Zero) { //Get Class from Path //Get IntPtr for Class ppCallResult = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(this); } ppObject = new IWbemClassObjectFreeThreaded(ppCallResult); return(0); }
public string GetText(TextFormat format) { string pstrObjectText = null; int errorCode = 0; switch (format) { case TextFormat.Mof: errorCode = this.wbemObject.GetObjectText_(0, out pstrObjectText); if (errorCode < 0) { if ((errorCode & 0xfffff000L) != 0x80041000L) { Marshal.ThrowExceptionForHR(errorCode); return(pstrObjectText); } ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode); } return(pstrObjectText); case TextFormat.CimDtd20: case TextFormat.WmiDtd20: { IWbemObjectTextSrc src = (IWbemObjectTextSrc) new WbemObjectTextSrc(); IWbemContext pCtx = (IWbemContext) new WbemContext(); pCtx.SetValue_("IncludeQualifiers", 0, true); pCtx.SetValue_("IncludeClassOrigin", 0, ref pValue); if (src != null) { errorCode = src.GetText_(0, (IWbemClassObject_DoNotMarshal)Marshal.GetObjectForIUnknown((IntPtr)this.wbemObject), (uint)format, pCtx, out pstrObjectText); if (errorCode < 0) { if ((errorCode & 0xfffff000L) != 0x80041000L) { Marshal.ThrowExceptionForHR(errorCode); return(pstrObjectText); } ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode); } } return(pstrObjectText); } } return(null); }
internal IWbemContext GetContext() { IWbemContext wbemContext = null; if (0 < this.Count) { int num = 0; try { wbemContext = (IWbemContext)(new WbemContext()); IEnumerator enumerator = this.GetEnumerator(); try { do { if (!enumerator.MoveNext()) { break; } string current = (string)enumerator.Current; object obj = base.BaseGet(current); num = wbemContext.SetValue_(current, 0, ref obj); }while (((long)num & (long)-2147483648) == (long)0); } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } catch { } } return(wbemContext); }
internal int CreateInstanceEnumAsync_(string strFilter, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { return this.pWbemServiecsSecurityHelper.CreateInstanceEnumAsync_(strFilter, lFlags, pCtx, pResponseHandler); }
int System.Management.IWbemServices_Old.PutInstance_(IWbemClassObject_DoNotMarshal pInst, int lFlags, IWbemContext pCtx, IntPtr ppCallResult) { return -2147217396; }
int System.Management.IWbemServices_Old.GetObjectAsync_(string strObjectPath, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\""); if (match.Success) { //match.Groups[1].Value; string value = match.Groups[2].Value; string str = match.Groups[3].Value; if (Instrumentation.ProcessIdentity == str) { int num = ((IConvertible)value).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int))); object item = null; try { InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1); item = InstrumentedAssembly.mapIDToPublishedObject[num.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int)))]; } finally { InstrumentedAssembly.readerWriterLock.ReleaseReaderLock(); } if (item != null) { Type type = (Type)this.instrumentedAssembly.mapTypeToConverter[item.GetType()]; if (type != null) { object obj = Activator.CreateInstance(type); ConvertToWMI convertToWMI = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), obj, "ToWMI"); lock (item) { convertToWMI(item); } IntPtr[] intPtrArray = new IntPtr[1]; intPtrArray[0] = (IntPtr)obj.GetType().GetField("instWbemObjectAccessIP").GetValue(obj); IntPtr[] intPtrArray1 = intPtrArray; Marshal.AddRef(intPtrArray1[0]); IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded(intPtrArray1[0]); object processIdentity = num; wbemClassObjectFreeThreaded.Put_("InstanceId", 0, ref processIdentity, 0); processIdentity = Instrumentation.ProcessIdentity; wbemClassObjectFreeThreaded.Put_("ProcessId", 0, ref processIdentity, 0); pResponseHandler.Indicate_(1, intPtrArray1); pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return 0; } } pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return -2147217406; } else { pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return -2147217406; } } else { pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return -2147217406; } }
int System.Management.IWbemServices_Old.ExecQueryAsync_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { return -2147217396; }
int System.Management.IWbemServices_Old.ExecMethodAsync_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObject_DoNotMarshal pInParams, IWbemObjectSink pResponseHandler) { return -2147217396; }
int System.Management.IWbemServices_Old.DeleteInstanceAsync_(string strObjectPath, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { return -2147217396; }
int System.Management.IWbemServices_Old.DeleteClass_(string strClass, int lFlags, IWbemContext pCtx, IntPtr ppCallResult) { return -2147217396; }
internal static int ExecQueryWmi(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { var svc = pCurrentNamespace as UnixWbemServices; IEnumerable<IWbemClassObject_DoNotMarshal> list = WMIDatabaseFactory.Get(svc.CurrentNamespace, strQuery); ppEnum = new UnixEnumWbemClassObject(list); return 0; }
internal static int ExecNotificationQueryWmi(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { ppEnum = null; return 0; }
internal int ExecNotificationQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, ref IEnumWbemClassObject ppEnum) { int num = -2147217407; if (this.scope != null) { num = WmiNetUtilsHelper.ExecNotificationQueryWmi_f(strQueryLanguage, strQuery, lFlags, pCtx, out ppEnum, (int) this.scope.Options.Authentication, (int) this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority); } return num; }
internal int ExecMethodAsync_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObjectFreeThreaded pInParams, IWbemObjectSink pResponseHandler) { return this.pWbemServiecsSecurityHelper.ExecMethodAsync_(strObjectPath, strMethodName, lFlags, pCtx, (IntPtr) pInParams, pResponseHandler); }
int IWbemServices_Old.CreateInstanceEnumAsync_([In][MarshalAs(UnmanagedType.BStr)] string strFilter, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { try { // Make sure we do not let a shutdown kill this thread preventShutdownLock.AcquireReaderLock(-1); // If we are already shutting down, don't do anything if (shutdownInProgress != 0) { return(0); } // If batching takes longer than 1/10 of a second, we want to stop // and flush the batch uint timeLimitForBatchFlush = (uint)Environment.TickCount + 100; // Find the managed type that is being requested by this call Type managedType = null; foreach (Type type in instrumentedAssembly.mapTypeToConverter.Keys) { if (0 == String.Compare(ManagedNameAttribute.GetMemberName(type), strFilter, StringComparison.Ordinal)) { managedType = type; break; } } // If we do not support the requested type, just exit if (null == managedType) { return(0); } // size for batching int batchSize = 64; // Array of IWbemClassObject IntPtrs for batching IntPtr[] objs = new IntPtr[batchSize]; IntPtr[] objsClone = new IntPtr[batchSize]; // Array of converter methods for batching ConvertToWMI[] funcs = new ConvertToWMI[batchSize]; // Array of IWbemClassObjectFreeThreaded instances for batching IWbemClassObjectFreeThreaded[] insts = new IWbemClassObjectFreeThreaded[batchSize]; // IWbemObjectAccess handle for 'InstanceId' int handleInstanceId = 0; // Current number of objects in batch int count = 0; // The process identity string Object processIdentity = Instrumentation.ProcessIdentity; // Walk all published instances try { // Don't let anyone add entries to the dictionary while we are enumerating it. // Other people can read from the dictionary InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1); foreach (DictionaryEntry entry in InstrumentedAssembly.mapIDToPublishedObject) { // If the process is going away, stop indicating more instances if (shutdownInProgress != 0) { return(0); } // Is this object the type requested by this query? if (managedType != entry.Value.GetType()) { continue; } // Initialize this batch entry if necessary. Each element of the batch arrays // are initialized 'just in time'. If we have less than batchSize entries total // (or it takes too long to batch), we do not unnecessarily allocate the batch entry if (funcs[count] == null) { Object converter = Activator.CreateInstance((Type)instrumentedAssembly.mapTypeToConverter[managedType]); funcs[count] = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), converter, "ToWMI"); // // Reuters VSQFE#: 750 [marioh] // In order for the instance data batching logic to work properly, we HAVE TO convert the .NET // objects to WMI objects before we update the batching pointers since the ToWMI method in the generated // code will Spawn new instances. // lock (entry.Value) funcs[count](entry.Value); objs[count] = (IntPtr)converter.GetType().GetField("instWbemObjectAccessIP").GetValue(converter); Marshal.AddRef(objs[count]); insts[count] = new IWbemClassObjectFreeThreaded(objs[count]); insts[count].Put_("ProcessId", 0, ref processIdentity, 0); int cimType; if (count == 0) { WmiNetUtilsHelper.GetPropertyHandle_f27(27, insts[count], "InstanceId", out cimType, out handleInstanceId); } } else { // // Reuters VSQFE#: 750 [marioh] // If we end up re-using an existing delegate from the batch array, we still have to convert // the .NET to WMI objects and update the instance pointers. // // Copy the managed instance information into the IWbemClassObject' // We're using a batch, therefore we have to convert them. lock (entry.Value) funcs[count](entry.Value); objs[count] = (IntPtr)funcs[count].Target.GetType().GetField("instWbemObjectAccessIP").GetValue(funcs[count].Target); // // We have to AddRef the interface pointer due to the IWbemClassObjectFreeThreaded not addreffing // but releasing in the destructor. Great huh? // Marshal.AddRef(objs[count]); insts[count] = new IWbemClassObjectFreeThreaded(objs[count]); insts[count].Put_("ProcessId", 0, ref processIdentity, 0); int cimType; if (count == 0) { WmiNetUtilsHelper.GetPropertyHandle_f27(27, insts[count], "InstanceId", out cimType, out handleInstanceId); } } // We have an instance to publish. Store the instance ID in 'InstanceId' string instanceId = (string)entry.Key; WmiNetUtilsHelper.WritePropertyValue_f28(28, insts[count], handleInstanceId, (instanceId.Length + 1) * 2, instanceId); // // Copy the managed instance information into the IWbemClassObject' // lock(entry.Value) // funcs[count](entry.Value); // Increment the batch counter count++; // If we've reached batchSize, or if we've gone longer than 1/10th second since // an Indicate, flush the batch if (count == batchSize || ((uint)Environment.TickCount) >= timeLimitForBatchFlush) { // Do the Indicate to WMI // NOTE: On WinXP, we cannot control whether the implementation of // Indicate will immediately send the objects to WMI, or if it will // batch them. If it batches them, we cannot reuse them in a future // call to Indicate, or change them in any way after the call to // Indicate. Because of this, we will always 'Clone' the objects // just before calling Indicate. The performance is negligable, even // on Windows 2000, which can handle about 200,000 Clones per second // on a 1 GHz machine. for (int i = 0; i < count; i++) { WmiNetUtilsHelper.Clone_f(12, objs[i], out objsClone[i]); } int hr = pResponseHandler.Indicate_(count, objsClone); for (int i = 0; i < count; i++) { Marshal.Release(objsClone[i]); } // If hr is not S_OK, we stop the enumeration. This can happen if the // client cancels the call. if (hr != 0) { return(0); } // Reset the batch counter count = 0; // Reset the time limit for another 1/10th second in the future timeLimitForBatchFlush = (uint)Environment.TickCount + 100; } } } finally { InstrumentedAssembly.readerWriterLock.ReleaseReaderLock(); } if (count > 0) { // NOTE: On WinXP, we cannot control whether the implementation of // Indicate will immediately send the objects to WMI, or if it will // batch them. If it batches them, we cannot reuse them in a future // call to Indicate, or change them in any way after the call to // Indicate. Because of this, we will always 'Clone' the objects // just before calling Indicate. The performance is negligable, even // on Windows 2000, which can handle about 200,000 Clones per second // on a 1 GHz machine. for (int i = 0; i < count; i++) { WmiNetUtilsHelper.Clone_f(12, objs[i], out objsClone[i]); } pResponseHandler.Indicate_(count, objsClone); for (int i = 0; i < count; i++) { Marshal.Release(objsClone[i]); } } } finally { pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); preventShutdownLock.ReleaseReaderLock(); } return(0); }
internal int DeleteInstanceAsync_(string strObjectPath, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { return this.pWbemServiecsSecurityHelper.DeleteInstanceAsync_(strObjectPath, lFlags, pCtx, pResponseHandler); }
public virtual extern HResult ConnectServer(string networkResource, string userName, string userPassword, string locale, WbemConnectOption wbemConnectOption, string authority, IWbemContext ctx, out IWbemServices wbemServices);
int System.Management.IWbemServices_Old.CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = null; return -2147217396; }
int System.Management.IWbemServices_Old.CreateInstanceEnumAsync_(string strFilter, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { Type type = null; int num; try { EventSource.preventShutdownLock.AcquireReaderLock(-1); if (EventSource.shutdownInProgress == 0) { int tickCount = Environment.TickCount + 100; foreach (Type key in this.instrumentedAssembly.mapTypeToConverter.Keys) { if (string.Compare(ManagedNameAttribute.GetMemberName(key), strFilter, StringComparison.Ordinal) != 0) { continue; } type = key; break; } if (null != type) { int num1 = 64; IntPtr[] value = new IntPtr[num1]; IntPtr[] intPtrArray = new IntPtr[num1]; ConvertToWMI[] convertToWMIArray = new ConvertToWMI[num1]; IWbemClassObjectFreeThreaded[] wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded[num1]; int num2 = 0; int V_8 = 0; object processIdentity = Instrumentation.ProcessIdentity; try { InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1); foreach (DictionaryEntry dictionaryEntry in InstrumentedAssembly.mapIDToPublishedObject) { if (EventSource.shutdownInProgress == 0) { if (type != dictionaryEntry.Value.GetType()) { continue; } if (convertToWMIArray[num2] != null) { lock (dictionaryEntry.Value) { convertToWMIArray[num2](dictionaryEntry.Value); } value[num2] = (IntPtr)convertToWMIArray[num2].Target.GetType().GetField("instWbemObjectAccessIP").GetValue(convertToWMIArray[num2].Target); Marshal.AddRef(value[num2]); wbemClassObjectFreeThreaded[num2] = new IWbemClassObjectFreeThreaded(value[num2]); wbemClassObjectFreeThreaded[num2].Put_("ProcessId", 0, ref processIdentity, 0); if (num2 == 0) { int V_15; WmiNetUtilsHelper.GetPropertyHandle_f27(27, wbemClassObjectFreeThreaded[num2], "InstanceId", out V_15, out V_8); } } else { object obj = Activator.CreateInstance((Type)this.instrumentedAssembly.mapTypeToConverter[type]); convertToWMIArray[num2] = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), obj, "ToWMI"); lock (dictionaryEntry.Value) { convertToWMIArray[num2](dictionaryEntry.Value); } value[num2] = (IntPtr)obj.GetType().GetField("instWbemObjectAccessIP").GetValue(obj); Marshal.AddRef(value[num2]); wbemClassObjectFreeThreaded[num2] = new IWbemClassObjectFreeThreaded(value[num2]); wbemClassObjectFreeThreaded[num2].Put_("ProcessId", 0, ref processIdentity, 0); if (num2 == 0) { int V_13; WmiNetUtilsHelper.GetPropertyHandle_f27(27, wbemClassObjectFreeThreaded[num2], "InstanceId", out V_13, out V_8); } } string str = (string)dictionaryEntry.Key; WmiNetUtilsHelper.WritePropertyValue_f28(28, wbemClassObjectFreeThreaded[num2], V_8, (str.Length + 1) * 2, str); num2++; if (num2 != num1 && Environment.TickCount < tickCount) { continue; } for (int i = 0; i < num2; i++) { WmiNetUtilsHelper.Clone_f(12, value[i], out intPtrArray[i]); } int num3 = pResponseHandler.Indicate_(num2, intPtrArray); for (int j = 0; j < num2; j++) { Marshal.Release(intPtrArray[j]); } if (num3 == 0) { num2 = 0; tickCount = Environment.TickCount + 100; } else { num = 0; return num; } } else { num = 0; return num; } } } finally { InstrumentedAssembly.readerWriterLock.ReleaseReaderLock(); } if (num2 > 0) { for (int k = 0; k < num2; k++) { WmiNetUtilsHelper.Clone_f(12, value[k], out intPtrArray[k]); } pResponseHandler.Indicate_(num2, intPtrArray); for (int l = 0; l < num2; l++) { Marshal.Release(intPtrArray[l]); } } return 0; } else { num = 0; } } else { num = 0; } } finally { pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); EventSource.preventShutdownLock.ReleaseReaderLock(); } return num; }
internal static int PutInstanceWmi(IntPtr pInst, int lFlags, IWbemContext pCtx, IntPtr ppCallResult, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { return pCurrentNamespace.PutInstance_ (pInst, lFlags, pCtx, ppCallResult); }
int System.Management.IWbemServices_Old.DeleteInstance_(string strObjectPath, int lFlags, IWbemContext pCtx, IntPtr ppCallResult) { return -2147217396; }
internal static int ConnectServerWmi(string strNetworkResource, string strUser, IntPtr strPassword, string strLocale, int lSecurityFlags, string strAuthority, IWbemContext pCtx, out IWbemServices ppNamespace, int impersonationLevel, int authenticationLevel) { WMIDatabaseFactory.EnsureOpen(); ppNamespace = new UnixWbemServices(); return 0; }
int System.Management.IWbemServices_Old.ExecMethod_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObject_DoNotMarshal pInParams, out IWbemClassObject_DoNotMarshal ppOutParams, IntPtr ppCallResult) { ppOutParams = null; return -2147217396; }
int IWbemServices_Old.GetObjectAsync_([In][MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In] Int32 lFlags, [In][MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In][MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler) { // pResponseHandler.SetStatus(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, null); // Marshal.ReleaseComObject(pResponseHandler); // return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND); Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\""); if (match.Success == false) { pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND)); } string className = match.Groups[1].Value; string instanceId = match.Groups[2].Value; string processId = match.Groups[3].Value; if (Instrumentation.ProcessIdentity != processId) { pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND)); } int id = ((IConvertible)instanceId).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32))); Object theObject = null; try { InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1); theObject = InstrumentedAssembly.mapIDToPublishedObject[id.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32)))]; } finally { InstrumentedAssembly.readerWriterLock.ReleaseReaderLock(); } if (theObject != null) { Type converterType = (Type)instrumentedAssembly.mapTypeToConverter[theObject.GetType()]; if (converterType != null) { Object converter = Activator.CreateInstance(converterType); ConvertToWMI func = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), converter, "ToWMI"); // // Regression: Reuters VSQFE#: 750, PS#141144 [marioh] // GetObjectAsync was missed. Again, here we have to call ToWMI before retrieving the pointer to the object // since we clone a new one during the ToWMI call. The code below was simply moved from a location further down // lock (theObject) func(theObject); // // END: Regression: Reuters VSQFE#: 750, PS#141144 [marioh] IntPtr[] objs = new IntPtr[] { (IntPtr)converter.GetType().GetField("instWbemObjectAccessIP").GetValue(converter) }; Marshal.AddRef(objs[0]); IWbemClassObjectFreeThreaded inst = new IWbemClassObjectFreeThreaded(objs[0]); Object o = id; inst.Put_("InstanceId", 0, ref o, 0); o = Instrumentation.ProcessIdentity; inst.Put_("ProcessId", 0, ref o, 0); // ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()]; // // Reuters VSQFE#: 750, PS#141144 [marioh] // The commented out code was moved up before accessing the object pointer in order to get the // newly cloned one. // // lock(theObject) // func(theObject); pResponseHandler.Indicate_(1, objs); pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return(0); } } pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND)); #if xxx IWbemClassObject classObj = null; IWbemCallResult result = null; pNamespace.GetObject("TestInstance", 0, pCtx, ref classObj, ref result); IWbemClassObject inst; classObj.SpawnInstance(0, out inst); TestInstance testInstance = (TestInstance)mapNameToTestInstance[match.Groups[1].Value]; Object o = (object)testInstance.name; inst.Put("name", 0, ref o, 0); o = (object)testInstance.value; inst.Put("value", 0, ref o, 0); pResponseHandler.Indicate(1, new IWbemClassObject[] { inst }); pResponseHandler.SetStatus_(0, 0, IntPtr.Zero, IntPtr.Zero); Marshal.ReleaseComObject(pResponseHandler); #endif }
int System.Management.IWbemServices_Old.ExecQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = null; return -2147217396; }
//****************************************************** //GetText //****************************************************** /// <summary> /// <para>Returns a textual representation of the object in the specified format.</para> /// </summary> /// <param name='format'>The requested textual format. </param> /// <returns> /// <para>The textual representation of the /// object in the specified format.</para> /// </returns> public string GetText(TextFormat format) { string objText = null; int status = (int)ManagementStatus.NoError; // // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on // its getter. // switch (format) { case TextFormat.Mof: status = wbemObject.GetObjectText_(0, out objText); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } return(objText); case TextFormat.CimDtd20: case TextFormat.WmiDtd20: //This may throw on non-XP platforms... - should we catch ? IWbemObjectTextSrc wbemTextSrc = (IWbemObjectTextSrc) new WbemObjectTextSrc(); IWbemContext ctx = (IWbemContext) new WbemContext(); object v = (bool)true; ctx.SetValue_("IncludeQualifiers", 0, ref v); ctx.SetValue_("IncludeClassOrigin", 0, ref v); if (wbemTextSrc != null) { status = wbemTextSrc.GetText_(0, (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(wbemObject)), (uint)format, //note: this assumes the format enum has the same values as the underlying WMI enum !! ctx, out objText); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } } return(objText); default: return(null); } }
int System.Management.IWbemServices_Old.GetObject_(string strObjectPath, int lFlags, IWbemContext pCtx, out IWbemClassObject_DoNotMarshal ppObject, IntPtr ppCallResult) { ppObject = null; return -2147217396; }
int System.Management.IWbemProviderInit.Initialize_(string wszUser, int lFlags, string wszNamespace, string wszLocale, IWbemServices pNamespace, IWbemContext pCtx, IWbemProviderInitSink pInitSink) { this.pNamespaceNA = pNamespace; this.RelocateNamespaceRCWToMTA(); this.pSinkNA = null; this.pSinkMTA = null; lock (this.mapQueryIdToQuery) { this.mapQueryIdToQuery.Clear(); } pInitSink.SetStatus_(0, 0); Marshal.ReleaseComObject(pInitSink); return 0; }
int System.Management.IWbemServices_Old.OpenNamespace_(string strNamespace, int lFlags, IWbemContext pCtx, out IWbemServices ppWorkingNamespace, IntPtr ppCallResult) { ppWorkingNamespace = null; return -2147217396; }
int System.Management.IWbemServices_Old.CreateClassEnumAsync_(string strSuperclass, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { return -2147217396; }
int System.Management.IWbemServices_Old.PutInstanceAsync_(IWbemClassObject_DoNotMarshal pInst, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { return -2147217396; }
internal int CreateClassEnumAsync_(string strSuperClass, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler) { return this.pWbemServiecsSecurityHelper.CreateClassEnumAsync_(strSuperClass, lFlags, pCtx, pResponseHandler); }