我已经编写了一个程序来检查它是否在特定的文件夹中;如果不在,它会将自己复制到该文件夹中,运行复制的程序并退出。但问题是,当我在复制的程序中调用Directory.GetCurrentDirectory();时(仅当它由第一个程序运行时),我得到的是第一个程序的目录,而不是复制的程序。这里有什么问题?
代码:
if(Directory.GetCurrentDirectory()!=dir)
{
File.Copy(Application.ExecutablePath,dir+name);
System.Diagnostics.Process.Start(dir+@"\"+name);
System.Environment.Exit(System.Environment.ExitCode);
}我总结了我的代码。
发布于 2012-03-13 15:48:24
你必须在processinfo上使用WorkingDirectory,不需要复制文件。
if(Directory.GetCurrentDirectory()!=dir)
{
string exepath = Path.Combine(dir,name);
ProcessStartInfo processStartInfo = new ProcessStartInfo();
process.StartInfo.FileName = exepath;
processStartInfo.WorkingDirectory = dir;
//Set your other process info properties
Process process = Process.Start(processStartInfo);
System.Environment.Exit(System.Environment.ExitCode);
}https://stackoverflow.com/questions/9680096
复制相似问题