zoukankan      html  css  js  c++  java
  • wmi with dot net

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Management;

    namespace GetSystemInfo
    {
        
    class GetSystemInfo
        {
            
    static void Main(string[] args)
            {
                
    if (1 != args.Length)
                {
                    
    return;
                }

                
    //
                
    // List Processes
                string strComputerName = args[0];
                
    string strScopePath = string.Format("\\\\{0}\\root\\cimv2", strComputerName);

                ManagementScope scope 
    = new ManagementScope(strScopePath);
                scope.Connect();
                ObjectQuery query 
    = new ObjectQuery("SELECT * FROM Win32_Process");
                ManagementObjectSearcher searcher 
    = new ManagementObjectSearcher(scope, query);
                ManagementObjectCollection colProcesses 
    = searcher.Get();

                
    foreach (ManagementObject oProcess in colProcesses)
                {
                    Console.WriteLine(
    "{0}\t{1}\t{2}", oProcess["ProcessId"], oProcess["Name"], oProcess["ExecutablePath"]);
                }

                
    //
                
    // Registry
                string strObjectPath = string.Format("\\\\{0}\\root\\DEFAULT:StdRegProv", strComputerName);
                ManagementClass oReg 
    = new ManagementClass(strObjectPath);
                
    object[] methodArgs = {0x80000002"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"null};
                
    object result = oReg.InvokeMethod("EnumValues", methodArgs);
                
    string[] arrValues = (string[])methodArgs[2];

                
    for (int i = 0; i < arrValues.Length; i++)
                {
                    
    object[] methodArgs1 = { 0x80000002"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", arrValues[i], null};
                    
    object result1 = oReg.InvokeMethod("GetStringValue", methodArgs1);
                    Console.WriteLine(
    "{0}\t{1}", arrValues[i], (string)methodArgs1[3]);
                }
            }
        }
    }
  • 相关阅读:
    有线电视网
    上帝造题的七分钟2 / 花神游历各国
    珂朵莉树(学习笔记)
    [SHOI2015]脑洞治疗仪
    语文1(chin1)- 理理思维
    [SCOI2010]序列操作
    CF915E Physical Education Lessons
    CF896C Willem, Chtholly and Seniorious
    Anaconda 创建环境
    非递归遍历N-ary树Java实现
  • 原文地址:https://www.cnblogs.com/luoluo/p/602403.html
Copyright © 2011-2022 走看看