我如何运行bat文件我刚添加到项目属性中的资源?

时间:2013-07-24 12:41:14

标签: c# winforms

我去了我的项目>属性>资源>添加现有文件> test.bat的 现在我有了这段代码:

private void Information()
{

}

我通过按钮点击事件调用此函数。

我想执行bat文件,因此每个使用我程序的用户都可以直接从程序中执行bat文件。 bat文件只是在特定目录中创建dxdiag.txt。

我该怎么做?

3 个答案:

答案 0 :(得分:1)

您可以将批处理文件放入可执行文件文件夹,然后使用the Process class,如下所示:

System.Diagnostics.Process.Start(System.IO.Path.Combine(Application.StartupPath, yourBatFileName));

请注意,通常根据您的配置将您的解决方案编译到Debug文件夹或Release文件夹中(因此您必须将文件放在正确的文件夹中)。

答案 1 :(得分:1)

使用此课程

Process.Start Method

答案 2 :(得分:0)

您可以使用以下参数...

var myProg = new System.Diagnostics.Process();
myProg .StartInfo.FileName = "file name with full path";   
myProg .StartInfo.UseShellExecute = false;
myProg .StartInfo.Arguments = "";
myProg .StartInfo.RedirectStandardOutput = true;
myProg .StartInfo.CreateNoWindow = true;
myProg .Start();
myProg .StandardOutput.ReadToEnd().Dump();