本文整理汇总了C#中System.Management.ManagementClass.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementClass.GetText方法的具体用法?C# ManagementClass.GetText怎么用?C# ManagementClass.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementClass
的用法示例。
在下文中一共展示了ManagementClass.GetText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewVM
public static ManagementObject NewVM(string VMName, string Server = null)
{
if (VMName == null)
return null;
var MgmtSvc = GetServiceObject(GetScope(Server), ServiceNames.VSManagement);
var settings = new ManagementClass(GetScope(Server),
new ManagementPath(VMStrings.GlobalSettingData),
new ObjectGetOptions()).CreateInstance();
if (settings == null)
return null;
settings["ElementName"] = VMName;
ManagementBaseObject inputs = MgmtSvc.GetMethodParameters("DefineVirtualSystem");
inputs["SystemSettingData"] = settings.GetText(TextFormat.WmiDtd20);
inputs["ResourceSettingData"] = null;
inputs["SourceSetting"] = null;
//var input = new object[] {settings.GetText(TextFormat.WmiDtd20), null, null, Comp, Job};
var result = MgmtSvc.InvokeMethod("DefineVirtualSystem", inputs, null);
switch (Int32.Parse(result["ReturnValue"].ToString()))
{
case (int)ReturnCodes.OK:
return GetObject(result["DefinedSystem"].ToString());
case (int)ReturnCodes.JobStarted:
return WaitForJob((ManagementObject)result["Job"]) == 0 ? GetObject(result["DefinedSystem"].ToString()) : null;
default:
return null;
}
}
示例2: ReplaceClassIfNecessary
private static void ReplaceClassIfNecessary(string classPath, ManagementClass newClass)
{
try
{
ManagementClass class2 = SafeGetClass(classPath);
if (class2 == null)
{
newClass.Put();
}
else if (newClass.GetText(TextFormat.Mof) != class2.GetText(TextFormat.Mof))
{
class2.Delete();
newClass.Put();
}
}
catch (ManagementException exception)
{
throw new ArgumentException(string.Format(RC.GetString("CLASS_NOTREPLACED_EXCEPT") + "\r\n{0}\r\n{1}", classPath, newClass.GetText(TextFormat.Mof)), exception);
}
}
示例3: ReplaceClassIfNecessary
private static void ReplaceClassIfNecessary(string classPath, ManagementClass newClass)
{
try
{
ManagementClass managementClass = SchemaNaming.SafeGetClass(classPath);
if (managementClass != null)
{
if (newClass.GetText(TextFormat.Mof) != managementClass.GetText(TextFormat.Mof))
{
managementClass.Delete();
newClass.Put();
}
}
else
{
newClass.Put();
}
}
catch (ManagementException managementException1)
{
ManagementException managementException = managementException1;
string str = string.Concat(RC.GetString("CLASS_NOTREPLACED_EXCEPT"), "\r\n{0}\r\n{1}");
throw new ArgumentException(string.Format(str, classPath, newClass.GetText(TextFormat.Mof)), managementException);
}
}
示例4: ReplaceClassIfNecessary
/// <summary>
/// Given a class path, and a ManagementClass class definition, this
/// function will create the class if it does not exist, replace the
/// class if it exists but is different, or do nothing if the class
/// exists and is identical. This is useful for performance reasons
/// since it can be expensive to delete an existing class and replace
/// it.
/// </summary>
/// <param name="classPath">WMI path to class</param>
/// <param name="newClass">Class to create or replace</param>
static void ReplaceClassIfNecessary(string classPath, ManagementClass newClass)
{
try
{
ManagementClass oldClass = SafeGetClass(classPath);
if(null == oldClass)
newClass.Put();
else
{
//
if(newClass.GetText(TextFormat.Mof) != oldClass.GetText(TextFormat.Mof))
{
//
oldClass.Delete();
newClass.Put();
}
}
}
catch(ManagementException e)
{
string strformat = RC.GetString("CLASS_NOTREPLACED_EXCEPT") + "\r\n{0}\r\n{1}";
throw new ArgumentException(String.Format(strformat, classPath, newClass.GetText(TextFormat.Mof)), e);
}
}