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


C# ManagementClass.Get方法代码示例

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


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

示例1: EnsureClassExists

		private static void EnsureClassExists(SchemaNaming.InstallLogWrapper context, string classPath, SchemaNaming.ClassMaker classMakerFunction)
		{
			try
			{
				context.LogMessage(string.Concat(RC.GetString("CLASS_ENSURE"), " ", classPath));
				ManagementClass managementClass = new ManagementClass(classPath);
				managementClass.Get();
			}
			catch (ManagementException managementException1)
			{
				ManagementException managementException = managementException1;
				if (managementException.ErrorCode != ManagementStatus.NotFound)
				{
					throw managementException;
				}
				else
				{
					context.LogMessage(string.Concat(RC.GetString("CLASS_ENSURECREATE"), " ", classPath));
					ManagementClass managementClass1 = classMakerFunction();
					managementClass1.Put();
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:23,代码来源:SchemaNaming.cs

示例2: Shutdown

        public void Shutdown()
        {
            ManagementBaseObject mboShutdown = null;
            ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
            mcWin32.Get();

            /* You can't shutdown without security privileges */
            mcWin32.Scope.Options.EnablePrivileges = true;
            ManagementBaseObject mboShutdownParams =
                     mcWin32.GetMethodParameters("Win32Shutdown");

            /* 0 = Log off the network.
             * 1 = Shut down the system.
             * 2 = Perform a full reboot of the system.
             * 4 = Force any applications to quit instead of prompting the user to close them.
             * 8 = Shut down the system and, if possible, turn the computer off. */

            /* Flag 1 means we want to shut down the system. Use "2" to reboot. */
            mboShutdownParams["Flags"] = "1";
            mboShutdownParams["Reserved"] = "0";
            foreach (ManagementObject manObj in mcWin32.GetInstances())
            {
                mboShutdown = manObj.InvokeMethod("Win32Shutdown",
                                               mboShutdownParams, null);
            }
        }
开发者ID:BillTheBest,项目名称:rhevUP,代码行数:26,代码来源:systemOperations.cs

示例3: Shutdown

        public static void Shutdown(string mode)
        {
            if (mode == "WMI")
            {
                ManagementBaseObject mboShutdown = null;
                ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
                mcWin32.Get();

                // Get Security Privilages
                mcWin32.Scope.Options.EnablePrivileges = true;
                ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");

                //Option Flags
                mboShutdownParams["Flags"] = "1";
                mboShutdownParams["Reserved"] = "0";
                foreach (ManagementObject manObj in mcWin32.GetInstances())
                {
                    mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
                }
            }
            else if (mode == "Core")
            {
                Process.Start("shutdown", "/s /t 0");
            }
        }
开发者ID:Porterbg,项目名称:Freeflex,代码行数:25,代码来源:Core.cs

示例4: ClearCache

        /// <summary>
        /// Clears the DNS Server cache of resource records. 
        /// </summary>
        /// <param name="server"></param>
        public static void ClearCache(Server server)
        {
            var cache = new ManagementClass(server.m_scope, new ManagementPath("MicrosoftDNS_Cache"), null);
            cache.Get();

            var coll = cache.GetInstances();

            List<Cache> cachelist = new List<Cache>();
            foreach (ManagementObject cacheobj in coll)
                cacheobj.InvokeMethod("ClearCache", null);
        }
开发者ID:drorgl,项目名称:MSDNSWebAdmin,代码行数:15,代码来源:Cache.cs

示例5: ExitWindows

 public static void ExitWindows(uint uFlags, uint dwReason)
 {
     ManagementBaseObject outParams = null;
     ManagementClass os = new ManagementClass("Win32_OperatingSystem");
     os.Get();
     os.Scope.Options.EnablePrivileges = true; // enables required security privilege.
     ManagementBaseObject inParams = os.GetMethodParameters("Win32Shutdown");
     inParams["Flags"] = uFlags.ToString();
     inParams["Reserved"] = "0";
     foreach (ManagementObject mo in os.GetInstances())
     {
         outParams = mo.InvokeMethod("Win32Shutdown",inParams, null);
     }
 }
开发者ID:mrsharpoblunto,项目名称:automaton,代码行数:14,代码来源:ShutDownUtils.cs

示例6: Shutdown

        /// <summary>
        /// Shutdown the computer
        /// </summary>
        public static void Shutdown()
        {
            ManagementClass managementClass = new ManagementClass("Win32_OperatingSystem");
            managementClass.Get();
            managementClass.Scope.Options.EnablePrivileges = true;

            ManagementBaseObject methodParameters = managementClass.GetMethodParameters("Win32Shutdown");
            methodParameters["Flags"] = "1";
            methodParameters["Reserved"] = "0";

            foreach (ManagementObject managementObject in managementClass.GetInstances())
            {
                managementObject.InvokeMethod("Win32Shutdown", methodParameters, null);
            }
        }
开发者ID:jbvigneron,项目名称:ShutDown,代码行数:18,代码来源:ShutdownHelper.cs

示例7: MainWindow_Closed

        private void MainWindow_Closed(object sender, EventArgs e)
        {
            if (MessageBox.Show("You must restart your computer to apply these changes.\nRestart now?", string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) {
                ManagementClass os = new ManagementClass("Win32_OperatingSystem");
                os.Get();
                os.Scope.Options.EnablePrivileges = true;
                ManagementBaseObject mboShutdownParams = os.GetMethodParameters("Win32Shutdown");
                mboShutdownParams["Flags"] = "6";
                mboShutdownParams["Reserved"] = "0";
                ManagementBaseObject obj;
                foreach (ManagementObject instance in os.GetInstances())
                    obj = instance.InvokeMethod("Win32Shutdown", mboShutdownParams, null);

            }
        }
开发者ID:minacle,项目名称:ReverseWheel,代码行数:15,代码来源:MainWindow.xaml.cs

示例8: ShutDownComputer

 public void ShutDownComputer(int flag)
 {
     ManagementBaseObject mboShutdown = null;
     ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
     mcWin32.Get();
     // You can't shutdown without security privileges
     mcWin32.Scope.Options.EnablePrivileges = true;
     ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");
     // Flag 1 means we want to shut down the system
     mboShutdownParams["Flags"] = flag;
     mboShutdownParams["Reserved"] = "0";
     foreach (ManagementObject manObj in mcWin32.GetInstances())
     {
         mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
     }
 }
开发者ID:Wobbley,项目名称:misc-timer,代码行数:16,代码来源:Actions.cs

示例9: Shutdown

        public static void Shutdown(ShutdownMode shutdownMode)
        {
            var mcWin32 = new ManagementClass("Win32_OperatingSystem");
            mcWin32.Get();

            // You can't shutdown without security privileges
            mcWin32.Scope.Options.EnablePrivileges = true;
            var mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");

            // Flag 1 means we want to shut down the system
            mboShutdownParams["Flags"] = ((int)shutdownMode).ToString(CultureInfo.InvariantCulture);
            mboShutdownParams["Reserved"] = "0";
            foreach (var manObj in mcWin32.GetInstances().Cast<ManagementObject>())
            {
                manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
            }
        }
开发者ID:gigaherz,项目名称:NPowerTray,代码行数:17,代码来源:PowerActions.cs

示例10: Execute

        public override void Execute(object context = null)
        {
            ActionsHomeModel pc = context as ActionsHomeModel;
            //Can only be processed if the machine is online...
            if (pc.Status == ComputerStates.Online || pc.Status == ComputerStates.LoggedOn)
            {
                ManagementScope oMs = ConnectToClient(pc.Name);
                if (oMs != null)
                {
                    this.DeleteQueryData(oMs, @"root\ccm\Policy", "SELECT * FROM CCM_SoftwareDistribution");
                    this.DeleteQueryData(oMs, @"root\ccm\Policy", "SELECT * FROM CCM_Scheduler_ScheduledMessage");
                    this.DeleteQueryData(oMs, @"root\ccm\Scheduler", "SELECT * FROM CCM_Scheduler_History");

                    //oMs.Path.NamespacePath = @"ROOT\CCM";
                    ManagementClass oClass = new ManagementClass(oMs, new ManagementPath("SMS_Client"), null);
                    oClass.Get();
                    ManagementBaseObject inParams = oClass.GetMethodParameters("ResetPolicy");
                    inParams["uFlags"] = 1;
                    oClass.InvokeMethod("ResetPolicy", inParams, new InvokeMethodOptions());

                    ManagementBaseObject newParams = oClass.GetMethodParameters("RequestMachinePolicy");
                    oClass.InvokeMethod("RequestMachinePolicy", newParams, new InvokeMethodOptions());

                    App.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.State = RemoteActionState.Completed;
                    }), null);
                }
                else
                {
                    App.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.State = RemoteActionState.Error;
                    }), null);
                }
            }
            else
            {
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    this.State = RemoteActionState.Pending;
                }), null);
            }
        }
开发者ID:przemo098,项目名称:ccmmanager,代码行数:44,代码来源:PolicyHardResetAction.cs

示例11: ShutDownComputer

 internal static void ShutDownComputer()
 {
     FindAndKillProcess("Wow");
     ManagementBaseObject outParameters = null;
     var sysOS = new ManagementClass("Win32_OperatingSystem");
     sysOS.Get();
     // enables required security privilege.
     sysOS.Scope.Options.EnablePrivileges = true;
     // get our in parameters
     ManagementBaseObject inParameters = sysOS.GetMethodParameters("Win32Shutdown");
     // pass the flag of 0 = System Shutdown
     inParameters["Flags"] = "1";
     inParameters["Reserved"] = "0";
     foreach (ManagementObject manObj in sysOS.GetInstances())
     {
         outParameters = manObj.InvokeMethod("Win32Shutdown", inParameters, null);
     }
     Environment.Exit(0);
 }
开发者ID:civicacid,项目名称:myevo,代码行数:19,代码来源:Shutdown.cs

示例12: Shutdown

        public static void Shutdown()
        {
            //http://stackoverflow.com/questions/102567/how-to-shutdown-the-computer-from-c-sharp
            ManagementBaseObject mboShutdown = null;
            ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
            mcWin32.Get();

            // You can't shutdown without security privileges
            mcWin32.Scope.Options.EnablePrivileges = true;
            ManagementBaseObject mboShutdownParams =
                     mcWin32.GetMethodParameters("Win32Shutdown");

            // Flag 1 means we want to shut down the system. Use "2" to reboot.
            mboShutdownParams["Flags"] = "1";
            mboShutdownParams["Reserved"] = "0";
            foreach (ManagementObject manObj in mcWin32.GetInstances())
            {
                mboShutdown = manObj.InvokeMethod("Win32Shutdown",
                                               mboShutdownParams, null);
            }
        }
开发者ID:shootsoft,项目名称:JustShutdown,代码行数:21,代码来源:Program.cs

示例13: ShutDown

        /// <summary>
        /// Shuts down the computer.
        /// </summary>
        /// <returns><c>true</c> if the computer was shut down successfully, or <c>false</c> otherwise.</returns>
        public static bool ShutDown()
        {
            try
            {
                ManagementClass os = new ManagementClass("Win32_OperatingSystem");
                os.Get();
                os.Scope.Options.EnablePrivileges = true;

                ManagementBaseObject parameters = os.GetMethodParameters("Win32Shutdown");
                parameters["Flags"] = "1"; // Shut down
                parameters["Reserved"] = "0";

                foreach (ManagementObject obj in os.GetInstances().Cast<ManagementObject>())
                {
                    obj.InvokeMethod("Win32Shutdown", parameters, null /* options */);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:Dziemborowicz,项目名称:Hourglass,代码行数:28,代码来源:WindowsExtensions.cs

示例14: CreateZone

        /// <summary>
        /// creates a DNS zone. 
        /// </summary>
        /// <param name="server">a Server instance</param>
        /// <param name="zoneName">String representing the name of the zone.</param>
        /// <param name="zoneType">Type of zone.</param>
        /// <param name="dsIntegrated">Indicates whether zone data is stored in the Active Directory or in files. If TRUE, the data is stored in the Active Directory; if FALSE, the data is stored in files.</param>
        /// <param name="dataFileName">Optional - Name of the data file associated with the zone.</param>
        /// <param name="ipAddr">Optional - IP address of the master DNS Server for the zone.</param>
        /// <param name="adminEmail">Optional - Email address of the administrator responsible for the zone.</param>
        /// <returns>the new Zone created</returns>
        public static Zone CreateZone(Server server,
                                string zoneName,
                                ZoneTypeCreate zoneType,
                                bool dsIntegrated,
                                string dataFileName,
                                string[] ipAddr,
                                string adminEmail)
        {
            if (server == null)
                throw new ArgumentNullException("server is required");

            try
            {
                ManagementObject mc = new ManagementClass(server.m_scope, new ManagementPath("MicrosoftDNS_Zone"), null);
                mc.Get();
                ManagementBaseObject parameters = mc.GetMethodParameters("CreateZone");
                parameters["ZoneName"] = zoneName;
                parameters["ZoneType"] = (UInt32)zoneType;
                parameters["DsIntegrated"] = dsIntegrated;
                if (!string.IsNullOrEmpty(dataFileName))
                    parameters["DataFileName"] = dataFileName;
                //if (!string.IsNullOrEmpty(ipAddr))
                parameters["IpAddr"] = ipAddr;
                if (!string.IsNullOrEmpty(adminEmail))
                    parameters["AdminEmailName"] = adminEmail;

                return new Zone(new ManagementObject(server.m_scope, new ManagementPath(mc.InvokeMethod("CreateZone", parameters, null)["RR"].ToString()), null));
            }
            catch (ManagementException me)
            {
                throw new WMIException(me);
            }
        }
开发者ID:drorgl,项目名称:MSDNSWebAdmin,代码行数:44,代码来源:Zone.cs

示例15: GetStatistics

 ///// <summary>
 ///// Gets all records
 ///// </summary>
 ///// <returns></returns>
 ////records are under zones, not server
 //public DNSManagement.RR.ResourceRecord[] GetRecords()
 //{
 //    var records = new ManagementClass(m_scope, new ManagementPath("MicrosoftDNS_ResourceRecord"), null);
 //    records.Get();
 //    var coll = records.GetInstances();
 //    List<DNSManagement.RR.ResourceRecord> recordlist = new List<DNSManagement.RR.ResourceRecord>();
 //    foreach (ManagementObject rhobj in coll)
 //        recordlist.Add(new DNSManagement.RR.ResourceRecord(rhobj));
 //    return recordlist.ToArray();
 //}
 /// <summary>
 /// Gets Statistics
 /// </summary>
 /// <returns></returns>
 public Statistic[] GetStatistics()
 {
     var statistics = new ManagementClass(m_scope, new ManagementPath("MicrosoftDNS_Statistic"), null);
     statistics.Get();
     var coll = statistics.GetInstances();
     List<Statistic> statisticlist = new List<Statistic>();
     foreach (ManagementObject stobj in coll)
         statisticlist.Add(new Statistic(stobj));
     return statisticlist.ToArray();
 }
开发者ID:drorgl,项目名称:MSDNSWebAdmin,代码行数:29,代码来源:Server.cs


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