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]);
                }
            }
        }
    }
  • 相关阅读:
    Redis-内存优化(一)
    window激活
    ArrayDeque原理详解
    CountDownLatch原理详解
    DelayQueue延迟队列原理剖析
    浅析PriorityBlockingQueue优先级队列原理
    修改QT库的路径
    数据同步Datax与Datax_web的部署以及使用说明
    HTTP头的Expires与Cache-control
    python生成随机数、随机字符串
  • 原文地址:https://www.cnblogs.com/luoluo/p/602403.html
Copyright © 2011-2022 走看看