Running the program with System.Diagnostics.Process.Start causes an application error

On my computers, DWG files open with:

"C:\Program Files\AutoCAD LT 2007\acadlt.exe" "%1"

If I run this from the command line:

"C:\Program Files\AutoCAD LT 2007\acadlt.exe" "C:\Some Path\Test.dwg"

AutoCAD Lite opens a DWG file.

Similarly, if I open a command prompt and run the same exe with an argument, it works fine.

However, if I use

var proc = new System.Diagnostics.Process();
var info = new System.Diagnostics.ProcessStartInfo();

and then

info.FileName = "C:\Some Path\Test.dwg";
proc.StartInfo = info;
proc.Start();

or

info.FileName = "C:\Program Files\AutoCAD LT 2007\acadlt.exe";
info.Arguments= "C:\Some Path\Test.dwg"
proc.StartInfo = info;
proc.Start();

or

info.FileName = "cmd.exe";
info.Arguments= "C:\Program Files\AutoCAD LT 2007\acadlt.exe" "C:\Some Path\Test.dwg"
proc.StartInfo = info;
proc.Start();

I get the following error:


acadlt.exe - Application Error

The command at "0x01317c8c" refers to the memory at "0x01317c8c". Memory cannot be read.

Click OK to end the program. Click "CANCEL" to debug the program.

Cancel OK


By the way, the code works fine if I go through the code using a debugger.

Does anyone know how I can use Process.Start to open this DWG?

+3
3

, Xenocode Postbuild . .NET exe ( ), . Xenocode .

0

, :

info.WorkingDirectory = "same path as current directory in cmd.exe";
+5

One of the differences between running from the command line and using it ProcessStartInfothis way is that the latter uses shell execution . I do not think that this can cause this problem, but it can cause problems. Try adding the following and see if it fixes the problem.

info.UseShellExecute = false;
+2
source

Source: https://habr.com/ru/post/1770414/


All Articles