3

On my PC 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 open the DWG file.

Similarly if I open a command prompt and run the same exe with 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 instruction at "0x01317c8c" referenced memory at "0x01317c8c". The memory could not be "read".

Click on OK to terminate the program Click on CANCEL to debug the program

OK Cancel


Incidentally the code works ok if I step through the code with the debugger.

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

Andrew Roberts
  • 990
  • 2
  • 12
  • 26

3 Answers3

5

Make sure to have the correct working folder specified:

info.WorkingDirectory = "same path as current directory in cmd.exe";
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • There isn't much of anything left. I always hated acad. – Hans Passant Oct 19 '10 at 23:36
  • This seems hard to get from code? http://stackoverflow.com/questions/217951/get-the-current-working-directory-for-cmd-exe – Andrew Roberts Oct 20 '10 at 01:03
  • If I set info.FileName = Environment.SystemDirectory + @"\cmd.exe"; info.Arguments= "echo %CD%" info.RedirectStandardOutput = true; the current directory (CD) is the same as Environment.CurrentDirectory. However if I run cmd.exe from the command prompt, CD is something completely different – Andrew Roberts Oct 20 '10 at 23:30
  • @Andrew Roberts: Sorry, I think you misunderstood my sample. You should use the same directory as when you start the process interactively from the console window. – Dirk Vollmar Oct 20 '10 at 23:35
2

One difference between launching from the command line and using ProcessStartInfo in this manner is that the latter uses shell execution. I don't think it's likely to be causing this problem but can cause issues. Try adding the following and seeing if it fixes the problem.

info.UseShellExecute = false;
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • Isn't the command line/shell per-se using `ShellExecute`/`ShellExecuteEx` which would be identical to calling `Process.Start` with `UseShellExecute = true;`? – Dirk Vollmar Oct 19 '10 at 21:42
  • @0xA3 if it's being launched from cmd.exe I don't *believe* it uses shell execution. The first example has an argument of `%1` which indicates a batch file of sorts and cmd. – JaredPar Oct 19 '10 at 21:43
  • The "%1" is just the syntax that Windows Explorer uses when displaying the settings in Registered File Types – Andrew Roberts Oct 20 '10 at 01:06
0

It turns out that it was Xenocode Postbuild causing the Application Error. If I run the same code on a normal .NET exe (not obfuscated), it works fine. I have referred to Xenocode for a solution.

Andrew Roberts
  • 990
  • 2
  • 12
  • 26