全部,
请原谅我对 C#/.NET 的无知,我对两者(主要是 Java、C/C++)都是全新的,并且发现自己的任务是创建一些代码来执行与“wmic qfe”和“wmic os”相同的事情"在 DOS 提示符下可用的命令。
这能做到吗?如果是这样,我们将不胜感激。我正在尝试通过 System.Management.Instrumentation 命名空间工作,因为 wmic 是 Windows Management Instrumentation Command 的首字母缩写词(根据 Google),但尚未发现任何有用的东西。
提前致谢, 托德夫
最佳答案
您可以简单地调用 wmic.exe,而不是使用 Management 类,它是一个 WMI 控制台,您可以从 exe 名称本身看出这一点。下面是我使用通过 C#.net 调用的 WMIC 在远程计算机上打开记事本的代码。试试吧。
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);
}
}
}
}
问候, 图沙尔
关于c# - wmic 通过 .NET 或 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3256405/