我编写了一个程序,它使用CorFlags.exe将应用程序从x86切换到x64并返回。我的程序具有管理员权限,Microsoft Visual Studio 2015也以管理员身份运行。我使用的是.NET Framework 4.5.2版。我检查了我在程序中使用的所有路径,所有路径都设置正确。最后,我的程序在x86下运行,而不是在Any CPU下运行。我的笔记本电脑运行Windows 7 Professionel(32位)。
现在这是我的问题,无论我做什么,每次运行程序时我都会收到错误“corflags:错误CF001:无法打开文件进行写入”。我在互联网上搜索了几个小时来解决这个问题,但没有任何东西可以帮我解决这个问题。更奇怪的是,当我逐步完成程序时,它工作正常,没有错误出现。只有当我正常运行程序而没有任何断点时,才会出现错误。我希望有人可以帮助我。这是我的计划:
string exePath = @"\CorFlags.exe";
exePath = Application.StartupPath + exePath;
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = exePath;
if (antwort == DialogResult.Yes)
{
Swapper selectedSwapper = bit_VersionControl1.SelectedVersion;
if (selectedSwapper.ID == 2)
{
process.StartInfo.Arguments = "/32BITPREF+ " + '"' + _strFilename + '"';
MessageBox.Show("32-Bit Version wird ausgeführt.");
}
else if (selectedSwapper.ID == 3)
{
process.StartInfo.Arguments = "/32BITPREF- " + '"' + _strFilename + '"';
MessageBox.Show("64-Bit Version wird ausgeführt.");
}
process.Start();
MessageBox.Show('"'+_strFilename+'"');
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
int result = process.ExitCode;
string errordetail = string.Empty;
我是C#的新手,所以请不要太难理解你的答案:D。谢谢你们。