如何将一些蝙蝠文件添加到我的项目中,这样我就不再需要硬盘上的文件了? [英] How can i add some bat files to my project so i will not need them anymore on the hard disk?
问题描述
例如,我有以下代码:
Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "dxdiag.bat";
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
proc.Close();
我是否从项目\debug目录中删除文件dxdiag.bat进行了测试在行上有一个异常:
I did a test if i delete the file dxdiag.bat from my project \debug directory im getting an exception on the line:
proc.Start();
找不到文件。
该文件位于\debug目录中后,即可正常工作。
That the file is not found. Once the file is in the \debug directory its working.
我想将dxdiag.bat文件添加到我的项目中,所以如果我发送给某人否则我的程序他将能够运行我的程序,并且该过程将从其自身的程序运行dxdiag.bat,因此我发送给该程序的程序将不需要bat文件位于其自己的硬盘上。
I want to add the dxdiag.bat file to my project so if i send to someone else my program he will be able run my program and the process will run the dxdiag.bat from the program it self so the one i sent the program wont need the bat file on his own hard disk.
推荐答案
只要您没有变量或非单行命令,就可以在bat文件的每一行中运行此功能
As long as you have no variables or nonsingleline-commands you can run this function with each line of the bat-file
internal static void executeCommand(string command, bool waitForExit,
bool hideWindow, bool runAsAdministrator)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("cmd", "/C " + command);
if (hideWindow)
{
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
}
if (runAsAdministrator)
{
psi.Verb = "runas";
}
if (waitForExit)
{
System.Diagnostics.Process.Start(psi).WaitForExit();
}
else
{
System.Diagnostics.Process.Start(psi);
}
}
所以您也可以将文本保存在代码中
so you can also save the text in the code
string bat_file = @"@echo off\ncopy c:\users\Desktop\filea.txt c:\users\Desktop\fileb.txt\n...";
否则,我将创建一个临时的bat文件,运行并删除它。
otherwise i would create a temporary bat file, run it and delete it.
这篇关于如何将一些蝙蝠文件添加到我的项目中,这样我就不再需要硬盘上的文件了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!