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


C# ConnectionOptions.Impersonation属性代码示例

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


在下文中一共展示了ConnectionOptions.Impersonation属性的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.
        // This example uses the default values.  
        ConnectionOptions options = 
            new ConnectionOptions();
        options.Impersonation = 
            System.Management.ImpersonationLevel.Impersonate;
                 
        // 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", 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,代码行数:49,代码来源:ConnectionOptions.Impersonation


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