C#的wmi问题
刚开始接触.net
用wmi启动进程写入文件的时候遇到难题
用网上现成的程序在本机测试失败(本机wmi可以访问,别的wmi管理工具都可以用)
望高手解难
using System;
using System.Management;
public class InvokeMethod
{
public static void Main()
{
ManagementClass processClass = new ManagementClass( "Win32_Process ");
ManagementBaseObject inParams = processClass.GetMethodParameters( "Create ");
inParams[ "CommandLine "] = "echo hello world > c:\\hello.txt ";
//就是上面这一步执行echo命令,进程启动总是失败,其他的命令又可以执行成功
ManagementBaseObject outParams = processClass.InvokeMethod( "Create ", inParams, null);
Console.WriteLine( "Creation of calculator process returned: " + outParams[ "returnvalue "]);
Console.WriteLine( "Process ID: " + outParams[ "processId "]);
}
}
------解决方案--------------------你是要直接通过 "echo hello world > c:\\hello.txt " 这个字符串写文件?
看看这个是否满足你的要求
inParams[ "CommandLine "] = "cmd.exe /c echo hello world > c:\\hello.txt ";