wmic via .NET or C#

徘徊边缘 提交于 2019-12-02 11:59:01

You will indeed need to use the System.Management namespace to perform WMI queries. There is lots info on using WMI from C#, Microsoft's is (archived) here

For your specific cases:

qfe - query the Win32_QuickFixEngineering class

os - query the Win32_OperatingSystem class

Instead of using the Management class, you can simply invoke the wmic.exe which is a WMI console as you can figure out from the exe name itself. Here is the code that I used to open notepad on a remote computer using WMIC invoked through C#.net. Try it out.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace RemoteProcessDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            string strComputerName = "";
            string strProcString = "";
            try
            {
                strComputerName = args[0];
                Process.Start("wmic", "/node:" + strComputerName + " process call create notepad.exe");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

Regards, Tushar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!