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


C# ManagementClass.Put方法代码示例

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


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

示例1: AddVirtualDirectory

        public void AddVirtualDirectory()
        {
            var siteId = 1574596940;
            //            var siteId = 1;
            var dir = "iplayer";
            var name = String.Format(@"W3SVC/{0}/root/{1}", siteId, dir);

            var vDir = new ManagementClass(Scope, new ManagementPath("IIsWebVirtualDirSetting"), null).CreateInstance();
            vDir["Name"] = name;
            vDir["Path"] = @"C:\sites\iplayer";
            vDir.Put();

            var path = string.Format("IIsWebVirtualDir.Name='{0}'", name);
            var app = new ManagementObject(Scope, new ManagementPath(path), null);
            app.InvokeMethod("AppCreate2", new object[] { 2 });

            vDir["AppPoolId"] = "GipRegForm.Api";
            vDir["AppFriendlyName"] = "stuff";
            vDir.Put();
        }
开发者ID:nbucket,项目名称:bounce,代码行数:20,代码来源:Iis6WebSiteTest.cs

示例2: CreateVirtualDirectory

        public IisVirtualDirectorySettings CreateVirtualDirectory(string subPath, string directory)
        {
            var path = String.Format(@"{0}/root/{1}", Name, subPath);

            var vDir = new ManagementClass(scope, new ManagementPath("IIsWebVirtualDirSetting"), null).CreateInstance();
            vDir["Name"] = path;
            vDir["Path"] = directory;
            vDir.Put();

            var virtualDirPath = string.Format("IIsWebVirtualDir.Name='{0}'", path);
            var app = new ManagementObject(scope, new ManagementPath(virtualDirPath), null);
            app.InvokeMethod("AppCreate2", new object[] { 2 });

            return new IisVirtualDirectorySettings(scope, path);
        }
开发者ID:haos11,项目名称:bounce,代码行数:15,代码来源:IisWebSite.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: Add

        public override void Add()
        {
            Log.Entry(LogName, "Attempting to add printer:");
            Log.Entry(LogName, string.Format("--> Name = {0}", Name));
            Log.Entry(LogName, string.Format("--> IP = {0}", IP));
            Log.Entry(LogName, string.Format("--> Port = {0}", Port));

            if (string.IsNullOrEmpty(IP) || !Name.StartsWith("\\\\")) return;

            if (IP.Contains(":"))
            {
                var arIP = IP.Split(':');
                if (arIP.Length == 2)
                {
                    IP = arIP[0];
                    Port = arIP[1];
                }
            }

            var conn = new ConnectionOptions
            {
                EnablePrivileges = true,
                Impersonation = ImpersonationLevel.Impersonate
            };

            var mPath = new ManagementPath("Win32_TCPIPPrinterPort");

            var mScope = new ManagementScope(@"\\.\root\cimv2", conn)
            {
                Options =
                {
                    EnablePrivileges = true,
                    Impersonation = ImpersonationLevel.Impersonate
                }
            };

            var mPort = new ManagementClass(mScope, mPath, null).CreateInstance();

            if (mPort != null)
            {
                mPort.SetPropertyValue("Name", "IP_" + IP);
                mPort.SetPropertyValue("Protocol", 1);
                mPort.SetPropertyValue("HostAddress", IP);
                mPort.SetPropertyValue("PortNumber", Port);
                mPort.SetPropertyValue("SNMPEnabled", false);

                var put = new PutOptions
                {
                    UseAmendedQualifiers = true,
                    Type = PutType.UpdateOrCreate
                };
                mPort.Put(put);
            }

            if (!Name.StartsWith("\\\\")) return;

            // Add per machine printer connection
            var proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /ga /n " + Name);
            if (proc != null) proc.WaitForExit(120000);
            // Add printer network connection, download the drivers from the print server
            proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /in /n " + Name);
            if (proc != null) proc.WaitForExit(120000);
        }
开发者ID:uw-it-cte,项目名称:fog-client,代码行数:63,代码来源:NetworkPrinter.cs

示例5: 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

示例6: RegisterProviderAsEventProvider

 private string RegisterProviderAsEventProvider(StringCollection events)
 {
     ManagementObject obj2 = new ManagementClass(this.EventProviderRegistrationClassPath).CreateInstance();
     obj2["provider"] = @"\\.\" + this.ProviderPath;
     string[] strArray = new string[events.Count];
     int num = 0;
     foreach (string str in events)
     {
         strArray[num++] = "select * from " + str;
     }
     obj2["EventQueryList"] = strArray;
     return obj2.Put().Path;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:SchemaNaming.cs

示例7: RegisterNamespaceAsInstrumented

 private void RegisterNamespaceAsInstrumented()
 {
     ManagementObject obj2 = new ManagementClass(this.GlobalRegistrationClassPath).CreateInstance();
     obj2["NamespaceName"] = this.NamespaceName;
     obj2.Put();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:6,代码来源:SchemaNaming.cs

示例8: RegisterAssemblySpecificDecoupledProviderInstance

 private void RegisterAssemblySpecificDecoupledProviderInstance()
 {
     ManagementObject obj2 = new ManagementClass(this.ProviderClassPath).CreateInstance();
     obj2["Name"] = this.DecoupledProviderInstanceName;
     obj2["HostingModel"] = "Decoupled:Com";
     if (this.SecurityDescriptor != null)
     {
         obj2["SecurityDescriptor"] = this.SecurityDescriptor;
     }
     obj2.Put();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:SchemaNaming.cs

示例9: RegisterAssemblyAsInstrumented

 private void RegisterAssemblyAsInstrumented()
 {
     ManagementObject obj2 = new ManagementClass(this.RegistrationClassPath).CreateInstance();
     obj2["Name"] = this.DecoupledProviderInstanceName;
     obj2["RegisteredBuild"] = this.AssemblyUniqueIdentifier;
     obj2["FullName"] = this.AssemblyName;
     obj2["PathToAssembly"] = this.AssemblyPath;
     obj2["Code"] = "";
     obj2["Mof"] = "";
     obj2.Put();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:SchemaNaming.cs

示例10: EnsureNamespace

 private static void EnsureNamespace(string baseNamespace, string childNamespaceName)
 {
     if (!DoesInstanceExist(baseNamespace + ":__NAMESPACE.Name=\"" + childNamespaceName + "\""))
     {
         ManagementObject obj2 = new ManagementClass(baseNamespace + ":__NAMESPACE").CreateInstance();
         obj2["Name"] = childNamespaceName;
         obj2.Put();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:SchemaNaming.cs

示例11: 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

示例12: EnsureClassExists

 static void EnsureClassExists(InstallLogWrapper context, string classPath, ClassMaker classMakerFunction)
 {
     try
     {
         context.LogMessage(RC.GetString("CLASS_ENSURE") + " " +classPath);
         ManagementClass theClass = new ManagementClass(classPath);
         theClass.Get();
     }
     catch(ManagementException e)
     {
         if(e.ErrorCode == ManagementStatus.NotFound)
         {
             // The class does not exist.  Create it.
             context.LogMessage(RC.GetString("CLASS_ENSURECREATE")+ " " +classPath);
             ManagementClass theClass = classMakerFunction();
             theClass.Put();
         }
         else
             throw e;
     }
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:21,代码来源:SchemaRegistration.cs

示例13: addIPPort

        private void addIPPort()
        {
            var conn = new ConnectionOptions
            {
                EnablePrivileges = true,
                Impersonation = ImpersonationLevel.Impersonate
            };

            var mPath = new ManagementPath("Win32_TCPIPPrinterPort");

            var mScope = new ManagementScope(@"\\.\root\cimv2", conn)
            {
                Options =
                {
                    EnablePrivileges = true,
                    Impersonation = ImpersonationLevel.Impersonate
                }
            };

            var mPort = new ManagementClass(mScope, mPath, null).CreateInstance();

            var remotePort = 9100;

            try
            {
                if (IP != null && IP.Contains(":"))
                {
                    var arIP = IP.Split(':');
                    if (arIP.Length == 2)
                        remotePort = int.Parse(arIP[1]);
                }
            }
            catch (Exception ex)
            {
                Log.Error(LogName, "Could not parse port from IP");
                Log.Error(LogName, ex);
            }

            mPort.SetPropertyValue("Name", Port);
            mPort.SetPropertyValue("Protocol", 1);
            mPort.SetPropertyValue("HostAddress", IP);
            mPort.SetPropertyValue("PortNumber", remotePort);
            mPort.SetPropertyValue("SNMPEnabled", false);

            var put = new PutOptions
            {
                UseAmendedQualifiers = true,
                Type = PutType.UpdateOrCreate
            };
            mPort.Put(put);
        }
开发者ID:snowsnail,项目名称:fog-client,代码行数:51,代码来源:LocalPrinter.cs

示例14: RegisterProviderAsInstanceProvider

 private string RegisterProviderAsInstanceProvider()
 {
     ManagementObject obj2 = new ManagementClass(this.InstanceProviderRegistrationClassPath).CreateInstance();
     obj2["provider"] = @"\\.\" + this.ProviderPath;
     obj2["SupportsGet"] = true;
     obj2["SupportsEnumeration"] = true;
     return obj2.Put().Path;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:SchemaNaming.cs

示例15: createOrUpdateWmi

        static void createOrUpdateWmi()
        {
            Console.WriteLine("Checking for namespace " + wmiNamespaceString+", and creating if missing");
            PutOptions options = new PutOptions();
            options.Type = PutType.UpdateOrCreate;
            ManagementClass objHostSettingClass = new ManagementClass("root\\cimv2", "__Namespace", null);
            ManagementObject wmiObject = objHostSettingClass.CreateInstance();
            wmiObject.SetPropertyValue("Name", wmiNamespaceName);
            wmiObject.Put(options);

            System.Management.ManagementClass wmiClass;
            try
            {
                wmiClass = new System.Management.ManagementClass(wmiNamespaceString, wmiClassString, null);
                wmiClass.CreateInstance();
                Console.WriteLine(wmiClassString + " class exists");
            }
            catch (ManagementException me)
            {
                Console.WriteLine(wmiClassString + " class does not exist, creating");
                wmiClass = new System.Management.ManagementClass(wmiNamespaceString, null, null);
                wmiClass["__CLASS"] = wmiClassString;
                wmiClass.Qualifiers.Add("Static", true);
                wmiClass.Put();

            }

            if (!testValueExists(wmiClass, "ManagedFolder"))
            {
                wmiClass.Properties.Add("ManagedFolder", System.Management.CimType.String, false);
                wmiClass.Properties["ManagedFolder"].Qualifiers.Add("Key", true);
            }
            if (!testValueExists(wmiClass, "MachineName")) { wmiClass.Properties.Add("MachineName", System.Management.CimType.String, false); }
            if (!testValueExists(wmiClass, "OverallState")) { wmiClass.Properties.Add("OverallState", System.Management.CimType.String, false); }
            if (!testValueExists(wmiClass, "OverallStateValue")) { wmiClass.Properties.Add("OverallStateValue", System.Management.CimType.UInt32, false); }
            if (!testValueExists(wmiClass, "FileCount")) { wmiClass.Properties.Add("FileCount", System.Management.CimType.UInt64, false); }

            if (!testValueExists(wmiClass, "NumberOfFilesFailingVerification")) { wmiClass.Properties.Add("NumberOfFilesFailingVerification", System.Management.CimType.UInt32, false); }
            if (!testValueExists(wmiClass, "VerificationFailureDetails")) { wmiClass.Properties.Add("VerificationFailureDetails", System.Management.CimType.String, false); }
            if (!testValueExists(wmiClass, "LastSuccessfulVerification")) { wmiClass.Properties.Add("LastSuccessfulVerification", System.Management.CimType.String, false); }
            if (!testValueExists(wmiClass, "VerifyNewImages")) { wmiClass.Properties.Add("VerifyNewImages", System.Management.CimType.Boolean, false); }
            if (!testValueExists(wmiClass, "ReverifyExistingImages")) { wmiClass.Properties.Add("ReverifyExistingImages", System.Management.CimType.Boolean, false); }
            if (!testValueExists(wmiClass, "ReverifyInterval")) { wmiClass.Properties.Add("ReverifyInterval", System.Management.CimType.SInt32, false); }

            if (!testValueExists(wmiClass, "ConsolidationEnabled")) { wmiClass.Properties.Add("ConsolidationEnabled", System.Management.CimType.Boolean, false); }
            if (!testValueExists(wmiClass, "LastSuccessfulConsolidation")) { wmiClass.Properties.Add("LastSuccessfulConsolidation", System.Management.CimType.String, false); }
            if (!testValueExists(wmiClass, "NumberOfFilesFailingConsolidation")) { wmiClass.Properties.Add("NumberOfFilesFailingConsolidation", System.Management.CimType.UInt32, false); }
            if (!testValueExists(wmiClass, "ConsolidationFailureDetails")) { wmiClass.Properties.Add("ConsolidationFailureDetails", System.Management.CimType.String, false); }

            if (!testValueExists(wmiClass, "FailedReplications")) { wmiClass.Properties.Add("FailedReplications", System.Management.CimType.UInt32, false); }
            if (!testValueExists(wmiClass, "NumberOfFilesQueuedForReplication")) { wmiClass.Properties.Add("NumberOfFilesQueuedForReplication", System.Management.CimType.UInt32, false); }
            if (!testValueExists(wmiClass, "ReplicationTargetDetails")) { wmiClass.Properties.Add("ReplicationTargetDetails", System.Management.CimType.String, false); }


            if (!testValueExists(wmiClass, "RetentionIssues")) { wmiClass.Properties.Add("RetentionIssues", System.Management.CimType.UInt32, false); }
            if (!testValueExists(wmiClass, "RetentionIssueDetails")) { wmiClass.Properties.Add("RetentionIssueDetails", System.Management.CimType.String, false); }
            if (!testValueExists(wmiClass, "RetentionEnabled")) { wmiClass.Properties.Add("RetentionEnabled", System.Management.CimType.Boolean, false); }
            if (!testValueExists(wmiClass, "RetentionPolicyInheritedFromGlobal")) { wmiClass.Properties.Add("RetentionPolicyInheritedFromGlobal", System.Management.CimType.Boolean, false); }
            if (!testValueExists(wmiClass, "DaysToRetainIntraDailyImages")) { wmiClass.Properties.Add("DaysToRetainIntraDailyImages", System.Management.CimType.SInt32, false); }
            if (!testValueExists(wmiClass, "DaysToRetainConsolidatedDailyImages")) { wmiClass.Properties.Add("DaysToRetainConsolidatedDailyImages", System.Management.CimType.SInt32, false); }
            if (!testValueExists(wmiClass, "DaysToRetainConsolidatedWeeklyImages")) { wmiClass.Properties.Add("DaysToRetainConsolidatedWeeklyImages", System.Management.CimType.SInt32, false); }
            if (!testValueExists(wmiClass, "MonthsToRetainConsolidatedMonthlyImages")) { wmiClass.Properties.Add("MonthsToRetainConsolidatedMonthlyImages", System.Management.CimType.SInt32, false); }
            if (!testValueExists(wmiClass, "DaysToRetainIntraDailyImages")) { wmiClass.Properties.Add("DaysToRetainIntraDailyImages", System.Management.CimType.SInt32, false); }
            if (!testValueExists(wmiClass, "MonthlyRetentionIsSupported")) { wmiClass.Properties.Add("MonthlyRetentionIsSupported", System.Management.CimType.Boolean, false); }
            if (!testValueExists(wmiClass, "MoveConsolidatedImages")) { wmiClass.Properties.Add("MoveConsolidatedImages", System.Management.CimType.Boolean, false); }


            if (!testValueExists(wmiClass, "FailedHeadstartJobs")) { wmiClass.Properties.Add("FailedHeadstartJobs", System.Management.CimType.UInt32, false); }
            if (!testValueExists(wmiClass, "HeadstartJobDetails")) { wmiClass.Properties.Add("HeadstartJobDetails", System.Management.CimType.String, false); }


            if (!testValueExists(wmiClass, "LastScriptRunTime")) { wmiClass.Properties.Add("LastScriptRunTime", System.Management.CimType.String, false); }
            if (!testValueExists(wmiClass, "Timestamp")) { wmiClass.Properties.Add("Timestamp", System.Management.CimType.UInt64, false); }
            if (!testValueExists(wmiClass, "ListOfAllManagedFolders")) { wmiClass.Properties.Add("ListOfAllManagedFolders", System.Management.CimType.String, false); }



            try
            {
                wmiClass.Put();
            }
            catch (ManagementException me)
            {
                if (me.ErrorCode.Equals(ManagementStatus.ClassHasInstances))
                {
                    Console.WriteLine("Deleting existing instances of " + wmiClassString);
                    ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiNamespaceString, "SELECT * FROM " + wmiClassString);
                    foreach (ManagementObject queryObj in searcher.Get())
                    {
                        queryObj.Delete();
                    }
                    wmiClass.Put();
                }
                else
                {
                    throw me;
                }
            }
        }
开发者ID:repl-helpdesk,项目名称:CustomMonitoring,代码行数:99,代码来源:Program.cs


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