本文整理汇总了C#中System.Management.ManagementClass.Derive方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementClass.Derive方法的具体用法?C# ManagementClass.Derive怎么用?C# ManagementClass.Derive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementClass
的用法示例。
在下文中一共展示了ManagementClass.Derive方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeRegistrationClass
private ManagementClass MakeRegistrationClass()
{
ManagementClass managementClass = new ManagementClass(this.InstrumentationClassPath);
ManagementClass managementClass1 = managementClass.Derive("WMINET_InstrumentedAssembly");
PropertyDataCollection properties = managementClass1.Properties;
properties.Add("Name", CimType.String, false);
PropertyData item = properties["Name"];
item.Qualifiers.Add("key", true);
properties.Add("RegisteredBuild", CimType.String, false);
properties.Add("FullName", CimType.String, false);
properties.Add("PathToAssembly", CimType.String, false);
properties.Add("Code", CimType.String, false);
properties.Add("Mof", CimType.String, false);
return managementClass1;
}
示例2: SchemaMapping
public SchemaMapping(Type type, SchemaNaming naming, Hashtable mapTypeToConverterClassName)
{
this.codeClassName = (string) mapTypeToConverterClassName[type];
this.classType = type;
bool flag = false;
string baseClassName = ManagedNameAttribute.GetBaseClassName(type);
this.className = ManagedNameAttribute.GetMemberName(type);
this.instrumentationType = InstrumentationClassAttribute.GetAttribute(type).InstrumentationType;
this.classPath = naming.NamespaceName + ":" + this.className;
if (baseClassName == null)
{
this.newClass = new ManagementClass(naming.NamespaceName, "", null);
this.newClass.SystemProperties["__CLASS"].Value = this.className;
}
else
{
ManagementClass class2 = new ManagementClass(naming.NamespaceName + ":" + baseClassName);
if (this.instrumentationType == System.Management.Instrumentation.InstrumentationType.Instance)
{
bool flag2 = false;
try
{
QualifierData data = class2.Qualifiers["abstract"];
if (data.Value is bool)
{
flag2 = (bool) data.Value;
}
}
catch (ManagementException exception)
{
if (exception.ErrorCode != ManagementStatus.NotFound)
{
throw;
}
}
if (!flag2)
{
throw new Exception(RC.GetString("CLASSINST_EXCEPT"));
}
}
this.newClass = class2.Derive(this.className);
}
CodeWriter writer = this.code.AddChild("public class " + this.codeClassName + " : IWmiConverter");
CodeWriter writer2 = writer.AddChild(new CodeWriter());
writer2.Line("static ManagementClass managementClass = new ManagementClass(@\"" + this.classPath + "\");");
writer2.Line("static IntPtr classWbemObjectIP;");
writer2.Line("static Guid iidIWbemObjectAccess = new Guid(\"49353C9A-516B-11D1-AEA6-00C04FB68820\");");
writer2.Line("internal ManagementObject instance = managementClass.CreateInstance();");
writer2.Line("object reflectionInfoTempObj = null ; ");
writer2.Line("FieldInfo reflectionIWbemClassObjectField = null ; ");
writer2.Line("IntPtr emptyWbemObject = IntPtr.Zero ; ");
writer2.Line("IntPtr originalObject = IntPtr.Zero ; ");
writer2.Line("bool toWmiCalled = false ; ");
writer2.Line("IntPtr theClone = IntPtr.Zero;");
writer2.Line("public static ManagementObject emptyInstance = managementClass.CreateInstance();");
writer2.Line("public IntPtr instWbemObjectAccessIP;");
CodeWriter writer3 = writer.AddChild("static " + this.codeClassName + "()");
writer3.Line("classWbemObjectIP = (IntPtr)managementClass;");
writer3.Line("IntPtr wbemObjectAccessIP;");
writer3.Line("Marshal.QueryInterface(classWbemObjectIP, ref iidIWbemObjectAccess, out wbemObjectAccessIP);");
writer3.Line("int cimType;");
CodeWriter writer4 = writer.AddChild("public " + this.codeClassName + "()");
writer4.Line("IntPtr wbemObjectIP = (IntPtr)instance;");
writer4.Line("originalObject = (IntPtr)instance;");
writer4.Line("Marshal.QueryInterface(wbemObjectIP, ref iidIWbemObjectAccess, out instWbemObjectAccessIP);");
writer4.Line("FieldInfo tempField = instance.GetType().GetField ( \"_wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic );");
writer4.Line("if ( tempField == null )");
writer4.Line("{");
writer4.Line(" tempField = instance.GetType().GetField ( \"wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic ) ;");
writer4.Line("}");
writer4.Line("reflectionInfoTempObj = tempField.GetValue (instance) ;");
writer4.Line("reflectionIWbemClassObjectField = reflectionInfoTempObj.GetType().GetField (\"pWbemClassObject\", BindingFlags.Instance | BindingFlags.NonPublic );");
writer4.Line("emptyWbemObject = (IntPtr) emptyInstance;");
CodeWriter writer5 = writer.AddChild("~" + this.codeClassName + "()");
writer5.AddChild("if(instWbemObjectAccessIP != IntPtr.Zero)").Line("Marshal.Release(instWbemObjectAccessIP);");
writer5.Line("if ( toWmiCalled == true )");
writer5.Line("{");
writer5.Line("\tMarshal.Release (originalObject);");
writer5.Line("}");
CodeWriter writer6 = writer.AddChild("public void ToWMI(object obj)");
writer6.Line("toWmiCalled = true ;");
writer6.Line("if(instWbemObjectAccessIP != IntPtr.Zero)");
writer6.Line("{");
writer6.Line(" Marshal.Release(instWbemObjectAccessIP);");
writer6.Line(" instWbemObjectAccessIP = IntPtr.Zero;");
writer6.Line("}");
writer6.Line("if(theClone != IntPtr.Zero)");
writer6.Line("{");
writer6.Line(" Marshal.Release(theClone);");
writer6.Line(" theClone = IntPtr.Zero;");
writer6.Line("}");
writer6.Line("IWOA.Clone_f(12, emptyWbemObject, out theClone) ;");
writer6.Line("Marshal.QueryInterface(theClone, ref iidIWbemObjectAccess, out instWbemObjectAccessIP) ;");
writer6.Line("reflectionIWbemClassObjectField.SetValue ( reflectionInfoTempObj, theClone ) ;");
writer6.Line(string.Format("{0} instNET = ({0})obj;", type.FullName.Replace('+', '.')));
writer.AddChild("public static explicit operator IntPtr(" + this.codeClassName + " obj)").Line("return obj.instWbemObjectAccessIP;");
writer2.Line("public ManagementObject GetInstance() {return instance;}");
PropertyDataCollection properties = this.newClass.Properties;
switch (this.instrumentationType)
{
//.........这里部分代码省略.........
示例3: MakeNamingClass
private ManagementClass MakeNamingClass()
{
ManagementClass managementClass = new ManagementClass(this.GlobalInstrumentationClassPath);
ManagementClass managementClass1 = managementClass.Derive("WMINET_Naming");
managementClass1.Qualifiers.Add("abstract", true);
PropertyDataCollection properties = managementClass1.Properties;
properties.Add("InstrumentedAssembliesClassName", "WMINET_InstrumentedAssembly", CimType.String);
return managementClass1;
}
示例4: MakeProviderClass
private ManagementClass MakeProviderClass()
{
ManagementClass managementClass = new ManagementClass(this.DecoupledProviderClassPath);
ManagementClass managementClass1 = managementClass.Derive("WMINET_ManagedAssemblyProvider");
PropertyDataCollection properties = managementClass1.Properties;
properties.Add("Assembly", CimType.String, false);
return managementClass1;
}
示例5: MakeDecoupledProviderClass
private ManagementClass MakeDecoupledProviderClass()
{
ManagementClass managementClass = new ManagementClass(this.Win32ProviderClassPath);
ManagementClass managementClass1 = managementClass.Derive("MSFT_DecoupledProvider");
PropertyDataCollection properties = managementClass1.Properties;
properties.Add("HostingModel", "Decoupled:Com", CimType.String);
properties.Add("SecurityDescriptor", CimType.String, false);
properties.Add("Version", 1, CimType.UInt32);
properties["CLSID"].Value = "{54D8502C-527D-43f7-A506-A9DA075E229C}";
return managementClass1;
}
示例6: MakeNamespaceRegistrationClass
private ManagementClass MakeNamespaceRegistrationClass()
{
ManagementClass managementClass = new ManagementClass(this.GlobalInstrumentationClassPath);
ManagementClass managementClass1 = managementClass.Derive("WMINET_InstrumentedNamespaces");
PropertyDataCollection properties = managementClass1.Properties;
properties.Add("NamespaceName", CimType.String, false);
PropertyData item = properties["NamespaceName"];
item.Qualifiers.Add("key", true);
return managementClass1;
}
示例7: MakeProviderClass
ManagementClass MakeProviderClass()
{
ManagementClass baseClass = new ManagementClass(DecoupledProviderClassPath);
ManagementClass newClass = baseClass.Derive(ProviderClassName);
PropertyDataCollection props = newClass.Properties;
props.Add("Assembly", CimType.String, false);
return newClass;
}
示例8: SchemaMapping
public SchemaMapping(Type type, SchemaNaming naming, Hashtable mapTypeToConverterClassName)
{
codeClassName = (string)mapTypeToConverterClassName[type];
classType = type;
bool hasGenericEmbeddedObject = false;
string baseClassName = ManagedNameAttribute.GetBaseClassName(type);
className = ManagedNameAttribute.GetMemberName(type);
instrumentationType = InstrumentationClassAttribute.GetAttribute(type).InstrumentationType;
classPath = naming.NamespaceName + ":" + className;
if(null == baseClassName)
{
newClass = new ManagementClass(naming.NamespaceName, "", null);
newClass.SystemProperties ["__CLASS"].Value = className;
}
else
{
ManagementClass baseClass = new ManagementClass(naming.NamespaceName + ":" + baseClassName);
if(instrumentationType == InstrumentationType.Instance)
{
bool baseAbstract = false;
try
{
QualifierData o = baseClass.Qualifiers["abstract"];
if(o.Value is bool)
baseAbstract = (bool)o.Value;
}
catch(ManagementException e)
{
if(e.ErrorCode != ManagementStatus.NotFound)
throw;
}
if(!baseAbstract)
throw new Exception(RC.GetString("CLASSINST_EXCEPT"));
}
newClass = baseClass.Derive(className);
}
// Create the converter class
CodeWriter codeClass = code.AddChild("public class "+codeClassName+" : IWmiConverter");
// Create code block for one line Members
CodeWriter codeOneLineMembers = codeClass.AddChild(new CodeWriter());
codeOneLineMembers.Line("static ManagementClass managementClass = new ManagementClass(@\"" + classPath + "\");");
codeOneLineMembers.Line("static IntPtr classWbemObjectIP;");
codeOneLineMembers.Line("static Guid iidIWbemObjectAccess = new Guid(\"49353C9A-516B-11D1-AEA6-00C04FB68820\");");
codeOneLineMembers.Line("internal ManagementObject instance = managementClass.CreateInstance();");
codeOneLineMembers.Line("object reflectionInfoTempObj = null ; ");
codeOneLineMembers.Line("FieldInfo reflectionIWbemClassObjectField = null ; ");
codeOneLineMembers.Line("IntPtr emptyWbemObject = IntPtr.Zero ; ");
codeOneLineMembers.Line("IntPtr originalObject = IntPtr.Zero ; ");
codeOneLineMembers.Line("bool toWmiCalled = false ; ");
//
// Reuters VSQFE#: 750 [marioh] see comments above
// Used as a temporary pointer to the newly created instance that we create to avoid re-using the same
// object causing unbound memory usage in IWbemClassObject implementation.
codeOneLineMembers.Line("IntPtr theClone = IntPtr.Zero;");
codeOneLineMembers.Line("public static ManagementObject emptyInstance = managementClass.CreateInstance();");
//
codeOneLineMembers.Line("public IntPtr instWbemObjectAccessIP;");
// Create static constructor to initialize handles
CodeWriter codeCCTOR = codeClass.AddChild("static "+codeClassName+"()");
codeCCTOR.Line("classWbemObjectIP = (IntPtr)managementClass;");
codeCCTOR.Line("IntPtr wbemObjectAccessIP;");
codeCCTOR.Line("Marshal.QueryInterface(classWbemObjectIP, ref iidIWbemObjectAccess, out wbemObjectAccessIP);");
codeCCTOR.Line("int cimType;");
// Create constructor
CodeWriter codeCTOR = codeClass.AddChild("public "+codeClassName+"()");
codeCTOR.Line("IntPtr wbemObjectIP = (IntPtr)instance;");
codeCTOR.Line("originalObject = (IntPtr)instance;");
codeCTOR.Line("Marshal.QueryInterface(wbemObjectIP, ref iidIWbemObjectAccess, out instWbemObjectAccessIP);");
//
// Reuters VSQFE#: 750 [marioh]
// In the CCTOR we set things up only once:
// 1. We get the IWbemClassObjectFreeThreaded object '_wbemObject' from the ManagementObject instance
// 2. We then get the actual IntPtr to the underlying WMI object
// 3. Finally, the simple cast to IntPtr from the ManagementObject instance
// These fields will be used later during the ToWMI call.
codeCTOR.Line ("FieldInfo tempField = instance.GetType().GetField ( \"_wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic );" );
codeCTOR.Line("if ( tempField == null )");
codeCTOR.Line("{");
codeCTOR.Line(" tempField = instance.GetType().GetField ( \"wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic ) ;");
codeCTOR.Line("}");
codeCTOR.Line ("reflectionInfoTempObj = tempField.GetValue (instance) ;");
codeCTOR.Line("reflectionIWbemClassObjectField = reflectionInfoTempObj.GetType().GetField (\"pWbemClassObject\", BindingFlags.Instance | BindingFlags.NonPublic );");
codeCTOR.Line("emptyWbemObject = (IntPtr) emptyInstance;");
// Create destructor that will be called at process cleanup
//.........这里部分代码省略.........
示例9: MakeDecoupledProviderClass
ManagementClass MakeDecoupledProviderClass()
{
ManagementClass baseClass = new ManagementClass(Win32ProviderClassPath);
ManagementClass newClass = baseClass.Derive(DecoupledProviderClassName);
PropertyDataCollection props = newClass.Properties;
props.Add("HostingModel", "Decoupled:Com", CimType.String);
props.Add("SecurityDescriptor", CimType.String, false);
props.Add("Version", 1, CimType.UInt32);
props["CLSID"].Value = DecoupledProviderCLSID;
return newClass;
}
示例10: MakeNamespaceRegistrationClass
ManagementClass MakeNamespaceRegistrationClass()
{
ManagementClass baseClass = new ManagementClass(GlobalInstrumentationClassPath);
ManagementClass newClass = baseClass.Derive(InstrumentedNamespacesClassName);
PropertyDataCollection props = newClass.Properties;
props.Add("NamespaceName", CimType.String, false);
PropertyData prop = props["NamespaceName"];
prop.Qualifiers.Add("key", true);
return newClass;
}
示例11: MakeRegistrationClass
ManagementClass MakeRegistrationClass()
{
ManagementClass baseClass = new ManagementClass(InstrumentationClassPath);
ManagementClass newClass = baseClass.Derive(InstrumentedAssembliesClassName);
PropertyDataCollection props = newClass.Properties;
props.Add("Name", CimType.String, false);
PropertyData prop = props["Name"];
prop.Qualifiers.Add("key", true);
props.Add("RegisteredBuild", CimType.String, false);
props.Add("FullName", CimType.String, false);
props.Add("PathToAssembly", CimType.String, false);
props.Add("Code", CimType.String, false);
props.Add("Mof", CimType.String, false);
return newClass;
}
示例12: MakeNamingClass
ManagementClass MakeNamingClass()
{
ManagementClass baseClass = new ManagementClass(GlobalInstrumentationClassPath);
ManagementClass newClass = baseClass.Derive(NamingClassName);
newClass.Qualifiers.Add("abstract", true);
PropertyDataCollection props = newClass.Properties;
props.Add("InstrumentedAssembliesClassName", InstrumentedAssembliesClassName, CimType.String);
return newClass;
}
示例13: SchemaMapping
public SchemaMapping(Type type, SchemaNaming naming, Hashtable mapTypeToConverterClassName)
{
int num;
bool flag;
MemberInfo memberInfo;
FieldInfo fieldInfo;
PropertyInfo propertyInfo;
MethodInfo getMethod;
string memberName;
Type propertyType;
bool flag1;
string str;
string item;
bool flag2;
DictionaryEntry dictionaryEntry;
string str1;
string str2;
CodeWriter codeWriter;
CodeWriter codeWriter1;
CodeWriter codeWriter2;
CodeWriter codeWriter3;
CodeWriter codeWriter4;
CodeWriter codeWriter5;
CodeWriter codeWriter6;
CodeWriter codeWriter7;
CodeWriter codeWriter8;
CodeWriter codeWriter9;
CodeWriter codeWriter10;
CodeWriter codeWriter11;
CodeWriter codeWriter12;
CimType cimType;
bool flag3;
PropertyData propertyDatum;
PropertyData item1;
PropertyData propertyDatum1;
MemberInfo[] members;
int i;
int num1;
this.code = new CodeWriter();
this.codeClassName = (string)mapTypeToConverterClassName[type];
this.classType = type;
bool flag4 = false;
string baseClassName = ManagedNameAttribute.GetBaseClassName(type);
this.className = ManagedNameAttribute.GetMemberName(type);
this.instrumentationType = InstrumentationClassAttribute.GetAttribute(type).InstrumentationType;
this.classPath = string.Concat(naming.NamespaceName, ":", this.className);
if (baseClassName != null)
{
ManagementClass managementClass = new ManagementClass(string.Concat(naming.NamespaceName, ":", baseClassName));
if (this.instrumentationType == InstrumentationType.Instance)
{
bool value = false;
try
{
QualifierData qualifierDatum = managementClass.Qualifiers["abstract"];
if (qualifierDatum.Value is bool)
{
value = (bool)qualifierDatum.Value;
}
}
catch (ManagementException managementException1)
{
ManagementException managementException = managementException1;
if (managementException.ErrorCode != ManagementStatus.NotFound)
{
throw;
}
}
if (!value)
{
throw new Exception(RC.GetString("CLASSINST_EXCEPT"));
}
}
this.newClass = managementClass.Derive(this.className);
}
else
{
this.newClass = new ManagementClass(naming.NamespaceName, "", null);
this.newClass.SystemProperties["__CLASS"].Value = this.className;
}
CodeWriter codeWriter13 = this.code.AddChild(string.Concat("public class ", this.codeClassName, " : IWmiConverter"));
CodeWriter codeWriter14 = codeWriter13.AddChild(new CodeWriter());
codeWriter14.Line(string.Concat("static ManagementClass managementClass = new ManagementClass(@\"", this.classPath, "\");"));
codeWriter14.Line("static IntPtr classWbemObjectIP;");
codeWriter14.Line("static Guid iidIWbemObjectAccess = new Guid(\"49353C9A-516B-11D1-AEA6-00C04FB68820\");");
codeWriter14.Line("internal ManagementObject instance = managementClass.CreateInstance();");
codeWriter14.Line("object reflectionInfoTempObj = null ; ");
codeWriter14.Line("FieldInfo reflectionIWbemClassObjectField = null ; ");
codeWriter14.Line("IntPtr emptyWbemObject = IntPtr.Zero ; ");
codeWriter14.Line("IntPtr originalObject = IntPtr.Zero ; ");
codeWriter14.Line("bool toWmiCalled = false ; ");
codeWriter14.Line("IntPtr theClone = IntPtr.Zero;");
codeWriter14.Line("public static ManagementObject emptyInstance = managementClass.CreateInstance();");
codeWriter14.Line("public IntPtr instWbemObjectAccessIP;");
CodeWriter codeWriter15 = codeWriter13.AddChild(string.Concat("static ", this.codeClassName, "()"));
codeWriter15.Line("classWbemObjectIP = (IntPtr)managementClass;");
codeWriter15.Line("IntPtr wbemObjectAccessIP;");
codeWriter15.Line("Marshal.QueryInterface(classWbemObjectIP, ref iidIWbemObjectAccess, out wbemObjectAccessIP);");
codeWriter15.Line("int cimType;");
CodeWriter codeWriter16 = codeWriter13.AddChild(string.Concat("public ", this.codeClassName, "()"));
//.........这里部分代码省略.........