File/Access 尝试从 C# 调用 VB6 应用程序时出错

File/Access Error when trying to call a VB6 application from c#

        ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + "MyExecutable.exe");            
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;            
        procStartInfo.CreateNoWindow = true;


        Process proc = new Process();
        proc.StartInfo = procStartInfo;
        proc.Start();

我的项目中有一个可执行文件,比如 "MyExecutable.exe"。当 运行 运行此应用程序时,它将在执行此 exe 的相同路径中创建一个日志文件。

如果我在命令提示符下 运行 这个 exe,我没有问题。

但是如果我 运行 来自 c# 代码的 exe,它会在下面的代码中抛出错误 "File/Access Error" MyExecutable.exe

Open `sLogfile` For Output Access Write As `LogFileNumber`

其中 sLogfilelogfile 名称,LogFileNumberFreeFile

当前的指南说不要将日志写入可执行目录。这可能是 Windows 执行此指南。改为写入用户的 AppData 目录。