本文整理汇总了C#中System.Management.ManagementScope类的典型用法代码示例。如果您正苦于以下问题:C# ManagementScope类的具体用法?C# ManagementScope怎么用?C# ManagementScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagementScope类属于System.Management命名空间,在下文中一共展示了ManagementScope类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Management;
public class RemoteConnect
{
public static void Main()
{
/*// Build an options object for the remote connection
// if you plan to connect to the remote
// computer with a different user name
// and password than the one you are currently using
ConnectionOptions options =
new ConnectionOptions();
// and then set the options.Username and
// options.Password properties to the correct values
// and also set
// options.Authority = "ntlmdomain:DOMAIN";
// and replace DOMAIN with the remote computer's
// domain. You can also use Kerberos instead
// of ntlmdomain.
*/
// Make a connection to a remote computer.
// Replace the "FullComputerName" section of the
// string "\\\\FullComputerName\\root\\cimv2" with
// the full computer name or IP address of the
// remote computer.
ManagementScope scope =
new ManagementScope(
"\\\\FullComputerName\\root\\cimv2");
scope.Connect();
// Use this code if you are connecting with a
// different user name and password:
//
// ManagementScope scope =
// new ManagementScope(
// "\\\\FullComputerName\\root\\cimv2", options);
// scope.Connect();
//Query system for Operating System information
ObjectQuery query = new ObjectQuery(
"SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope,query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach ( ManagementObject m in queryCollection)
{
// Display the remote computer information
Console.WriteLine("Computer Name : {0}",
m["csname"]);
Console.WriteLine("Windows Directory : {0}",
m["WindowsDirectory"]);
Console.WriteLine("Operating System: {0}",
m["Caption"]);
Console.WriteLine("Version: {0}", m["Version"]);
Console.WriteLine("Manufacturer : {0}",
m["Manufacturer"]);
}
}
}
开发者ID:.NET开发者,项目名称:System.Management,代码行数:64,代码来源:ManagementScope
注:本文中的System.Management.ManagementScope类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论