当前位置: 首页>>代码示例>>C#>>正文


C# ManagementClass.GetText方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:virmitio,项目名称:TempRepo,代码行数:27,代码来源:Utility.cs

示例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);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:SchemaNaming.cs

示例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);
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:25,代码来源:SchemaNaming.cs

示例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);
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:35,代码来源:SchemaRegistration.cs


注:本文中的System.Management.ManagementClass.GetText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。