带有cmd.exe的ProcessStartInfo无法在Main_Load中运行 [英] ProcessStartInfo with cmd.exe fails to run inside Main_Load

查看:211
本文介绍了带有cmd.exe的ProcessStartInfo无法在Main_Load中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助解决以下代码的错误吗?

Can someone please help what's wrong with the below code?

命令运行但是失败并且Results.txt显示"WMI存储库验证失败"
错误代码:  0x8007007E"。

Command runs, but fails and Results.txt displayes "WMI repository verification failed
Error code:  0x8007007E".

我不能将Main_Load用作静态因为我在此命令完成后也调用饼图,如果Main_Load为静态则不会运行。

I cannot use Main_Load as Static because I am also calling Pie Chart after this command completes and that doesn't run if Main_Load is Static.

namespace Test
    {
    public partial class Test : Form
        {
        public const string WMIFile = @"C:\\Testing\\Results.txt";
        private string anyCommand;

        public Test()
            {
            InitializeComponent();
            }
 

	public void Main_Load(object sender, EventArgs e)
            {
            
             ProcessStartInfo WMI = new ProcessStartInfo
                {
                UseShellExecute = true,
                CreateNoWindow = false,
                FileName = @"cmd.exe",
                };
            RunCmd = @"/c " + "WMI /verifyrepository > + WMIFile;
            WMI.Arguments = RunCmd;
            WMI.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(WMI);
            Thread.Sleep(2000);

            }

        }

    }




推荐答案

我测试了你提供的代码,但它没有发生任何测试中的错误。

I tested the code you provided, but it didn’t occur any error in the test.

    RunCmd = @"/c " + "WMI /verifyrepository > + WMIFile;

我注意到你使用了"WMI"在参数中,但"WMI"不被识别为内部或外部命令。它只是您刚刚创建的对象。

I notice that you use "WMI" in arguments, but 'WMI' is not recognized as an internal or external command. It is only an object you create just now.

此外,您可以对"WMIFile"进行以下更改。

Besides, maybe you can make the following changes to "WMIFile".

    public const string WMIFile = "C:\\Testing\\Results.txt"

>> ...在此命令完成后调用饼图,如果Main_Load为静态,则不会运行。

>> … calling Pie Chart after this command completes and that doesn't run if Main_Load is Static.

您能否具体说明哪一个不运行? "Main_Load"是指"Main_Load"。或"饼图"?

Could you specifically explain which one doesn't run? The "Main_Load" or "Pie Chart"?

如果"Main_Load"如果没有运行,您可以修改"Test.Designer.cs"中的代码。像这样:

If "Main_Load" doesn’t run, you can modify the code in "Test.Designer.cs" like this:

    //this.Load += new System.EventHandler(this.Main_Load);
    this.Load += new System.EventHandler(Main_Load);

如果是"饼图"没有运行,如果你能提供更多相关代码会更好。

If "Pie Chart" doesn’t run, it would be better if you can provide more related code.

问候,

Kyle


这篇关于带有cmd.exe的ProcessStartInfo无法在Main_Load中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆