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


C# ManagementClass.CreateInstance方法代码示例

本文整理汇总了C#中System.Management.ManagementClass.CreateInstance方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementClass.CreateInstance方法的具体用法?C# ManagementClass.CreateInstance怎么用?C# ManagementClass.CreateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementClass的用法示例。


在下文中一共展示了ManagementClass.CreateInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InstallHosts

        public static string InstallHosts(string ServerName, string HostName, string UserName, string Password, bool StartHost)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            ObjectGetOptions bts_objOptions = new ObjectGetOptions();

            // Creating instance of BizTalk Host.
            ManagementClass bts_AdminObjClassServerHost = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_ServerHost", bts_objOptions);
            ManagementObject bts_AdminObjectServerHost = bts_AdminObjClassServerHost.CreateInstance();

            // Make sure to put correct Server Name,username and // password
            bts_AdminObjectServerHost["ServerName"] = ServerName;
            bts_AdminObjectServerHost["HostName"] = HostName;
            bts_AdminObjectServerHost.InvokeMethod("Map", null);

            ManagementClass bts_AdminObjClassHostInstance = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostInstance", bts_objOptions);
            ManagementObject bts_AdminObjectHostInstance = bts_AdminObjClassHostInstance.CreateInstance();

            bts_AdminObjectHostInstance["Name"] = "Microsoft BizTalk Server " + HostName + " " + ServerName;

            //Also provide correct user name and password.
            ManagementBaseObject inParams = bts_AdminObjectHostInstance.GetMethodParameters("Install");
            inParams["GrantLogOnAsService"] = false;
            inParams["Logon"] = UserName;
            inParams["Password"] = Password;

            bts_AdminObjectHostInstance.InvokeMethod("Install", inParams, null);
            
            if(StartHost)
                bts_AdminObjectHostInstance.InvokeMethod("Start", null);

            return "  Host - " + HostName + " - has been installed. \r\n";
        }
开发者ID:navkar,项目名称:BizTalkControlCenter,代码行数:33,代码来源:WMIMethods.cs

示例2: addComputerToCollection

        protected void addComputerToCollection(string resourceID, string collectionID)
        {
            /*  Set collection = SWbemServices.Get ("SMS_Collection.CollectionID=""" & CollID &"""")

                  Set CollectionRule = SWbemServices.Get("SMS_CollectionRuleDirect").SpawnInstance_()
                  CollectionRule.ResourceClassName = "SMS_R_System"
                  CollectionRule.RuleName = "Static-"&ResourceID
                  CollectionRule.ResourceID = ResourceID
                  collection.AddMembershipRule CollectionRule*/

            //o.Properties["ResourceID"].Value.ToString();

            var pathString = "\\\\srv-cm12-p01.srv.aau.dk\\ROOT\\SMS\\site_AA1" + ":SMS_Collection.CollectionID=\"" + collectionID + "\"";
            ManagementPath path = new ManagementPath(pathString);
            ManagementObject obj = new ManagementObject(path);

            ManagementClass ruleClass = new ManagementClass("\\\\srv-cm12-p01.srv.aau.dk\\ROOT\\SMS\\site_AA1" + ":SMS_CollectionRuleDirect");

            ManagementObject rule = ruleClass.CreateInstance();

            rule["RuleName"] = "Static-"+ resourceID;
            rule["ResourceClassName"] = "SMS_R_System";
            rule["ResourceID"] = resourceID;

            obj.InvokeMethod("AddMembershipRule", new object[] { rule });
        }
开发者ID:yrke,项目名称:AAUWebMgmt,代码行数:26,代码来源:ComputerInfo.aspx.cs

示例3: AddInstance

        public void AddInstance(string wmiClass, string parametersJSON)
        {
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                object result = serializer.Deserialize(parametersJSON, typeof(object));

                Dictionary<string, object> dic = (Dictionary<string, object>)result;

                WindowsImpersonationContext impersonatedUser = WindowsIdentity.GetCurrent().Impersonate();

                ManagementClass genericClass = new ManagementClass(Scope, wmiClass, null);

                ManagementObject genericInstance = genericClass.CreateInstance();

                foreach (KeyValuePair<string, object> value in dic)
                {
                    genericInstance[value.Key] = value.Value.ToString();
                }

                genericInstance.Put();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
                log.LogError(ex.ToString());
            }
        }
开发者ID:nicoriff,项目名称:NinoJS,代码行数:28,代码来源:WMI.cs

示例4: Create

        /// <summary>
        /// Create a Send Handler.
        /// </summary>
        /// <param name="adapterName">The Adapter name.</param>
        /// <param name="hostName">The Host name.</param>
        /// <param name="isDefault">Indicating if the Handler is the default.</param>
        public static void Create(string adapterName, string hostName, bool isDefault)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            using (ManagementClass handlerManagementClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_SendHandler2", null))
            {
                foreach (ManagementObject handler in handlerManagementClass.GetInstances())
                {
                    if ((string)handler["AdapterName"] == adapterName && (string)handler["HostName"] == hostName)
                    {
                        handler.Delete();
                    }
                }

                ManagementObject handlerInstance = handlerManagementClass.CreateInstance();
                if (handlerInstance == null)
                {
                    throw new CoreException("Could not create Management Object.");
                }

                handlerInstance["AdapterName"] = adapterName;
                handlerInstance["HostName"] = hostName;
                handlerInstance["IsDefault"] = isDefault;
                handlerInstance.Put(options);
            }
        }
开发者ID:StealFocus,项目名称:Core,代码行数:32,代码来源:SendHandler.cs

示例5: Create

        /// <summary>
        /// Create a Receive Handler.
        /// </summary>
        /// <param name="adapterName">The Adapter name.</param>
        /// <param name="hostName">The Host name.</param>
        public static void Create(string adapterName, string hostName)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            using (ManagementClass handlerManagementClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_ReceiveHandler", null))
            {
                foreach (ManagementObject handler in handlerManagementClass.GetInstances())
                {
                    if ((string)handler["AdapterName"] == adapterName && (string)handler["HostName"] == hostName)
                    {
                        handler.Delete();
                    }
                }

                ManagementObject recieveHandlerManager = handlerManagementClass.CreateInstance();
                if (recieveHandlerManager == null)
                {
                    throw new BizTalkExtensionsException("Could not create Management Object.");
                }

                recieveHandlerManager["AdapterName"] = adapterName;
                recieveHandlerManager["HostName"] = hostName;
                recieveHandlerManager.Put(options);
            }
        }
开发者ID:StealFocus,项目名称:BizTalkExtensions,代码行数:30,代码来源:ReceiveHandler.cs

示例6: MakeHost

        public static string MakeHost(string HostName, string Type, string HostNTGroup, bool AuthTrusted)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;

            // create a ManagementClass object and spawn a ManagementObject instance
            ManagementClass objHostSettingClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostSetting", null);
            ManagementObject objHostSetting = objHostSettingClass.CreateInstance();

            // set the properties for the Managementobject
            // Host Name
            objHostSetting["Name"] = HostName;
            
            // Host Type
            if(Type == "Isolated")
                objHostSetting["HostType"] = HostType.Isolated;
            else
                objHostSetting["HostType"] = HostType.InProcess;

            objHostSetting["NTGroupName"] = HostNTGroup;

            objHostSetting["AuthTrusted"] = AuthTrusted;

            //create the Managementobject
            objHostSetting.Put(options);

            return Type + " Host - " + HostName + " - has been created. \r\n";
        }
开发者ID:navkar,项目名称:BizTalkControlCenter,代码行数:28,代码来源:WMIMethods.cs

示例7: CreateInstance

 public static ManagementObject CreateInstance(String scope, String className)
 {
     if(String.IsNullOrEmpty(scope))
     {
         throw new ArgumentNullException("scope");
     }
     if (String.IsNullOrEmpty(className))
     {
         throw new ArgumentNullException("className");
     }
     ManagementClass clazz = new ManagementClass(scope, className, null);
     return clazz.CreateInstance();
 }
开发者ID:biapar,项目名称:enhanced-monitoring-service,代码行数:13,代码来源:WMIHelper.cs

示例8: ConfigureMetricsFlushInterval

        ConfigureMetricsFlushInterval(
            TimeSpan interval)
        {
            ManagementScope scope = new ManagementScope(@"root\virtualization\v2");

            //
            // Create an instance of the Msvm_MetricServiceSettingData class and set the specified
            // metrics flush interval. Note that the TimeSpan must be converted to a DMTF time
            // interval first.
            //
            string dmtfTimeInterval = ManagementDateTimeConverter.ToDmtfTimeInterval(interval);

            string serviceSettingDataEmbedded;

            using (ManagementClass serviceSettingDataClass = new ManagementClass(
                "Msvm_MetricServiceSettingData"))
            {
                serviceSettingDataClass.Scope = scope;

                using (ManagementObject serviceSettingData = serviceSettingDataClass.CreateInstance())
                {
                    serviceSettingData["MetricsFlushInterval"] = dmtfTimeInterval;

                    serviceSettingDataEmbedded = serviceSettingData.GetText(TextFormat.WmiDtd20);
                }
                
            }
            
            //
            // Call the Msvm_MetricService::ModifyServiceSettings method. Note that the 
            // Msvm_MetricServiceSettingData instance must be passed as an embedded instance.
            //
            using (ManagementObject metricService = MetricUtilities.GetMetricService(scope))
            {
                using (ManagementBaseObject inParams = 
                    metricService.GetMethodParameters("ModifyServiceSettings"))
                {
                    inParams["SettingData"] = serviceSettingDataEmbedded;

                    using (ManagementBaseObject outParams = 
                        metricService.InvokeMethod("ModifyServiceSettings", inParams, null))
                    {
                        WmiUtilities.ValidateOutput(outParams, scope);

                        Console.WriteLine(string.Format(CultureInfo.CurrentCulture,
                            "The MetricsFlushInterval was successfully configured to interval \"{0}\".",
                            interval.ToString()));
                    }
                }
            }
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:51,代码来源:ModifyServiceSettings.cs

示例9: TestCreate

 private void TestCreate()
 {
     ConnectionOptions Conn = new ConnectionOptions();
     //Conn.Username = "wmitest";
     //Conn.Password = "wmitest";
     Conn.Impersonation = ImpersonationLevel.Impersonate;
     Conn.EnablePrivileges = true;
     ManagementScope ms = new ManagementScope(@"\\.\root\sbs", Conn);
     ms.Connect();
     ObjectGetOptions option = new ObjectGetOptions();
     ManagementClass mc = new ManagementClass(ms, new ManagementPath("sbs_user"), option);
     ManagementObject mo = mc.CreateInstance();
     mo["UserName"] = "aaa";
     mo.Put();
 }
开发者ID:cpm2710,项目名称:cellbank,代码行数:15,代码来源:Client.cs

示例10: CreateOutboundThrottlePolicy

        /// <summary>
        /// Sets the limit for the upload network data rate. This limit is applied for the specified user.
        /// This method is not reentrant. Remove the policy first after creating it again.
        /// </summary>
        private static void CreateOutboundThrottlePolicy(string ruleName, string windowsUsername, long bitsPerSecond)
        {
            var StandardCimv2 = new ManagementScope(@"root\StandardCimv2");

            using (ManagementClass netqos = new ManagementClass("MSFT_NetQosPolicySettingData"))
            {
                netqos.Scope = StandardCimv2;

                using (ManagementObject newInstance = netqos.CreateInstance())
                {
                    newInstance["Name"] = ruleName;
                    newInstance["UserMatchCondition"] = windowsUsername;

                    // ThrottleRateAction is in bytesPerSecond according to the WMI docs.
                    // Acctualy the units are bits per second, as documented in the PowerShell cmdlet counterpart.
                    newInstance["ThrottleRateAction"] = bitsPerSecond;

                    newInstance.Put();
                }
            }
        }
开发者ID:datatonic,项目名称:cf-windows-prison,代码行数:25,代码来源:Network.cs

示例11: NewVM

        public static void NewVM(string serverName, string vmName)
        {
            ManagementPath classPath = new ManagementPath()
            {
                Server = serverName,
                NamespacePath = @"\root\virtualization\v2",
                ClassName = "Msvm_VirtualSystemSettingData"
            };

            using (ManagementClass virtualSystemSettingClass = new ManagementClass(classPath))
            {
                Credentials.conOpts.Username = Credentials.username;
                Credentials.conOpts.SecurePassword = Credentials.password;
                Credentials.conOpts.Authority = Credentials.domain;
                Credentials.conOpts.Impersonation = ImpersonationLevel.Impersonate;

                ManagementScope scope = new ManagementScope(@"\\" + serverName + @"\root\virtualization\v2", Credentials.conOpts);

                virtualSystemSettingClass.Scope = scope;

                using (ManagementObject virtualSystemSetting = virtualSystemSettingClass.CreateInstance())
                {
                    virtualSystemSetting["ElementName"] = vmName;
                    virtualSystemSetting["VirtualsystemSubtype"] = "Microsoft:Hyper-V:Subtype:2";

                    string embeddedInstance = virtualSystemSetting.GetText(TextFormat.WmiDtd20);

                    using (ManagementObject service = Functions.getVMManagementService(scope))
                    using (ManagementBaseObject inParams = service.GetMethodParameters("DefineSystem"))
                    {
                        inParams["SystemSettings"] = embeddedInstance;

                        using (ManagementBaseObject outParams = service.InvokeMethod("DefineSystem", inParams, null))
                        {
                            Console.WriteLine("ret={0}", outParams["ReturnValue"]);
                        }
                    }
                }
            }
        }
开发者ID:jeffpatton1971,项目名称:mod-hyperv,代码行数:40,代码来源:HyperV.cs

示例12: CreateGeneration2VM

        CreateGeneration2VM(
            string serverName,
            string vmName)
        {
            ManagementPath classPath = new ManagementPath()
            {
                Server = serverName,
                NamespacePath = @"\root\virtualization\v2",
                ClassName = "Msvm_VirtualSystemSettingData"
            };

            using (ManagementClass virtualSystemSettingClass = new ManagementClass(classPath))
            {
                ManagementScope scope = new ManagementScope(@"\\" + serverName + @"\root\virtualization\v2", null);

                virtualSystemSettingClass.Scope = scope;

                using (ManagementObject virtualSystemSetting = virtualSystemSettingClass.CreateInstance())
                {
                    virtualSystemSetting["ElementName"] = vmName;
                    virtualSystemSetting["ConfigurationDataRoot"] = "C:\\ProgramData\\Microsoft\\Windows\\Hyper-V\\";
                    virtualSystemSetting["VirtualSystemSubtype"] = "Microsoft:Hyper-V:SubType:2";

                    string embeddedInstance = virtualSystemSetting.GetText(TextFormat.WmiDtd20);

                    // Get the management service, VM object and its settings.
                    using (ManagementObject service = WmiUtilities.GetVirtualMachineManagementService(scope))
                    using (ManagementBaseObject inParams = service.GetMethodParameters("DefineSystem"))
                    {
                        inParams["SystemSettings"] = embeddedInstance;

                        using (ManagementBaseObject outParams = service.InvokeMethod("DefineSystem", inParams, null))
                        {
                            Console.WriteLine("ret={0}", outParams["ReturnValue"]);
                        }
                    }
                }
            }
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:39,代码来源:CreateVM.cs

示例13: Add

        /// <summary>
        /// Adds the specified name.
        /// </summary>
        /// <param name="name">The name of the Adapter.</param>
        /// <param name="managementClassId">The management class ID.</param>
        /// <param name="comment">The comment.</param>
        public static void Add(string name, Guid managementClassId, string comment)
        {
            using (ManagementClass addAdapter_objClass = new ManagementClass(@"root\MicrosoftBizTalkServer", "MSBTS_AdapterSetting", new ObjectGetOptions()))
            {
                ManagementObject addAdapter_objInstance = addAdapter_objClass.CreateInstance();
                if (addAdapter_objInstance == null)
                {
                    throw new CoreException("Could not create Management Object.");
                }

                addAdapter_objInstance.SetPropertyValue("Name", name);

                // "B" GUID format example - "{9A7B0162-2CD5-4F61-B7EB-C40A3442A5F8}"
                addAdapter_objInstance.SetPropertyValue("MgmtCLSID", managementClassId.ToString("B"));
                if (!string.IsNullOrEmpty(comment))
                {
                    addAdapter_objInstance.SetPropertyValue("Comment", comment);
                }

                addAdapter_objInstance.Put();
            }
        }
开发者ID:StealFocus,项目名称:Core,代码行数:28,代码来源:Adapter.cs

示例14: newVhd

        public static void newVhd(string serverName, string diskType, string diskFormat, string path, string parentPath, int maxInternalSize, int blockSize, int logicalSectorSize, int physicalSectorSize)
        {
            ManagementPath classPath = new ManagementPath()
            {
                Server = serverName,
                NamespacePath = @"\root\virtualization\v2",
                ClassName = "Msvm_VirtualHardDiskSettingData"
            };

            using (ManagementClass settingsClass = new ManagementClass(classPath))
            {
                Credentials.conOpts.Username = Credentials.username;
                Credentials.conOpts.SecurePassword = Credentials.password;
                Credentials.conOpts.Authority = Credentials.domain;
                Credentials.conOpts.Impersonation = ImpersonationLevel.Impersonate;

                ManagementScope scope = new ManagementScope(@"\\" + serverName + @"\root\virtualization\v2", Credentials.conOpts);

                settingsClass.Scope = scope;
                using (ManagementObject settingsInstance = settingsClass.CreateInstance())
                {
                    settingsInstance["Type"] = diskType;
                    settingsInstance["Format"] = diskFormat;
                    settingsInstance["Path"] = path;
                    settingsInstance["ParentPath"] = parentPath;
                    settingsInstance["MaxInternalSize"] = maxInternalSize;
                    settingsInstance["BlockSize"] = blockSize;
                    settingsInstance["LogicalSectorSize"] = logicalSectorSize;
                    settingsInstance["PhysicalSectorSize"] = physicalSectorSize;

                    string settingsInstanceString = settingsInstance.GetText(TextFormat.WmiDtd20);

                    // return settingsInstanceString;
                }
            }
        }
开发者ID:jeffpatton1971,项目名称:mod-hyperv,代码行数:36,代码来源:HyperV.cs

示例15: SetWmiInstanceGetObject

 /// <summary>
 /// Set wmi instance helper
 /// </summary>
 internal ManagementObject SetWmiInstanceGetObject(ManagementPath mPath, string serverName)
 {
     ConnectionOptions options = GetConnectionOption();
     ManagementObject mObject = null;
     var setObject = this as SetWmiInstance;
     if (setObject != null)
     {
         if (setObject.Path != null)
         {
             mPath.Server = serverName;
             ManagementScope mScope = new ManagementScope(mPath, options);
             if (mPath.IsClass)
             {
                 ManagementClass mClass = new ManagementClass(mPath);
                 mClass.Scope = mScope;
                 mObject = mClass.CreateInstance();
             }
             else
             {
                 //This can throw if path does not exist caller should catch it.
                 ManagementObject mInstance = new ManagementObject(mPath);
                 mInstance.Scope = mScope;
                 try
                 {
                     mInstance.Get();
                 }
                 catch (ManagementException e)
                 {
                     if (e.ErrorCode != ManagementStatus.NotFound)
                     {
                         throw;
                     }
                     int namespaceIndex = setObject.Path.IndexOf(':');
                     if (namespaceIndex == -1)
                     {
                         throw;
                     }
                     int classIndex = (setObject.Path.Substring(namespaceIndex)).IndexOf('.');
                     if (classIndex == -1)
                     {
                         throw;
                     }
                     //Get class object and create instance.
                     string newPath = setObject.Path.Substring(0, classIndex + namespaceIndex);
                     ManagementPath classPath = new ManagementPath(newPath);
                     ManagementClass mClass = new ManagementClass(classPath);
                     mClass.Scope = mScope;
                     mInstance = mClass.CreateInstance();
                 }
                 mObject = mInstance;
             }
         }
         else
         {
             ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(serverName, setObject.Namespace), options);
             ManagementClass mClass = new ManagementClass(setObject.Class);
             mClass.Scope = scope;
             mObject = mClass.CreateInstance();
         }
         if (setObject.Arguments != null)
         {
             IDictionaryEnumerator en = setObject.Arguments.GetEnumerator();
             while (en.MoveNext())
             {
                 mObject[en.Key as string] = en.Value;
             }
         }
     }
     return mObject;
 }
开发者ID:dfinke,项目名称:powershell,代码行数:73,代码来源:WMIHelper.cs


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