简体   繁体   English

尝试从 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();

I have an executable in my project, say "MyExecutable.exe".我的项目中有一个可执行文件,例如“MyExecutable.exe”。 When running this application, it will create a log file in the same path where this exe is executed.运行此应用程序时,它将在执行此exe的同一路径中创建一个日志文件。

If I run this exe in command prompt, I have no issues.如果我在命令提示符下运行这个exe ,我没有问题。

But If I run the exe from c# code, it is throwing error "File/Access Error" in the below code which is in MyExecutable.exe但是,如果我从 c# 代码运行 exe,则会在MyExecutable.exe中的以下代码中引发错误“文件/访问错误”

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

where sLogfile is the logfile name and LogFileNumber is the FreeFile .其中sLogfilelogfile名, LogFileNumberFreeFile

Current guidance says to not write logs into an executable directory.当前指南说不要将日志写入可执行目录。 This is probably Windows enforcing this guidance.这可能是执行此指南的 Windows。 Write to the user's AppData directory instead.改为写入用户的AppData目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM