.msi를 설치하고 C# 코드를 통해 해당 cmd 파일을 실행하는 cmd 파일을 만들려고합니다. Visual Studio에서 f5 또는 control + f5를 사용하여 실행하면 코드가 완벽하게 작동합니다.프로그래밍 방식으로 명령 파일 만들기/실행
그러나 일단 코드를 .msi 파일에 패키지화하고 설치하면 (wpf 앱) 관련 코드가 실행될 때 명령 창이 열리지 만 명령을 실행하지 않습니다. "C : \ Program이 내부 또는 외부 명령으로 인식되지 않습니다 ..."라고 말합니다.이 오류는 파일 경로 주위에 따옴표가 없지만 따옴표 아래에서 볼 수있는 경우가 아니라는 것을 의미합니다. 거기 있어요. 또한 프로그램 파일 디렉터리로 이동하면 Reinstall.cmd 파일이 나타나며 따옴표가 붙습니다. 생성 된 Reinstall.cmd 파일을 두 번 클릭해도 제대로 실행됩니다. 나는 무엇을 여기에서 놓치고 있냐?? 따옴표가 아래 당신이 볼 수있는
private string MSIFilePath = Path.Combine(Environment.CurrentDirectory, "HoustersCrawler.msi");
private string CmdFilePath = Path.Combine(Environment.CurrentDirectory, "Reinstall.cmd");
private void CreateCmdFile()
{
//check if file exists.
if (File.Exists(CmdFilePath))
File.Delete(CmdFilePath);
//create new file.
var fi = new FileInfo(CmdFilePath);
var fileStream = fi.Create();
fileStream.Close();
//write commands to file.
using (TextWriter writer = new StreamWriter(CmdFilePath))
{
writer.WriteLine(String.Format("msiexec /i \"{0}\"", MSIFilePath));// /quiet
}
}
private void RunCmdFile()
{//run command file to reinstall app.
var p = new Process();
p.StartInfo = new ProcessStartInfo("cmd.exe", "/k " + CmdFilePath);
p.Start();
p.WaitForExit();
}