2

I need to start AutoCAD from a windows service. This service is running with a "special" domain user, which is created for just running my service. This user is admin on the machine, and this user installed AutoCAD 2014 on the machine. The code I'm using to start AutoCAD 2014 from C#:

  IAcadApplication acadApp;
  try
  {
    var acadType = Type.GetTypeFromProgID("AutoCAD.Application.19", true);
    acadApp = (AcadApplication) Activator.CreateInstance(acadType, true);
  }
  catch (Exception ex)
  {
    // do fancy error handling here
  }

I have a reference to the AutoCAD COM library. (Interop.AutoCAD.dll) If I run the above code with my logged in user, AutoCAD starts and I can do anything I want with SendCommand. If I put it in a service (see Update), start the service with my "special" user the CreateInstance command throws this:

{"Retrieving the COM class factory for component with CLSID {BD0DEB94-63DB-4392-9420-6EEE05094B1F} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."}

The thing is, that acad.exe starts, but stops consuming memory around 44 MBytes, and after 1-2 minutes, I get the exception. Usually, acad.exe starts with 112 MByte of memory consumed. If I run the service in the logged in user's name, everything works as expected. Both users are in the same user groups, same domain. So my code is essentially works. But the goal is, to have a server program, that can run AutoCAD stuff. How can I run AutoCAD on a server in this scenario? According to some posts around the net, this can be caused by access rights problems. But what rights do I have to give to the "special" user?

UPDATE: As I posted it on the official Autodesk forum, I can't start AutoCAD from a service. The user does not matter. Someone on the official forum stated, that AutoCAD can not be run from a service. Either this, or something with the licensing could cause this behaviour... Altough, I'm still open for any solution to start AutoCAD from a service. (Windows Service hosted WCF, to be more precise.)

UDPATE2: Since I did not find a solution for the problem, and AutoCAD does not stop with a useful error message, I solved this without using Windows Service. Currently I'm hosting my WCF solution in a command prompt solution, and running it as a user. This is as ugly as it gets. I can't even count the probelms it will bring. But deadlines are deadlines... I'm still open for real solutions.

AntiTalent
  • 101
  • 1
  • 9
  • The OP has added new information here: http://forums.autodesk.com/t5/NET/Start-AutoCAD-with-interop-but-with-different-user/m-p/4815925 – Owen Wengerd Feb 15 '14 at 04:51
  • May I ask why do you need to start Autocad from a Service. Since you start it from a Service, I belive you don't need to have User Interaction with it. What do you need to do, that involves running Autocad as a Service? – Paulo Correia Feb 17 '14 at 12:29
  • @PauloCorreia: We need to run a LISP program **automatically**. It receives some input values (Excel), and do a complex design. We don't need user interaction. (Never said we need it...) My problem is: using interop in a service, I can't create an instance of AutoCAD (can't start it), so I can't do anything with it. – AntiTalent Feb 18 '14 at 13:06

2 Answers2

1

The problem here is the persona required to run COM API... a Windows service will not have this...

You may try automation with AutoCAD Console, check accoreconsole.exe at the AutoCAD folder. You'll need to create a script file that contains the list of command that you want to run (including .NET custom command) then launch the console to run this script.

Should work.

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • Wow. Didn't know about that tool. Googling it -> seems [promising](http://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console.html). I will try it as soon as I have the time. Thanks for posting this. If it does work, I'll definitely mark your answer as a solution. – AntiTalent May 15 '15 at 08:38
  • We did end up using accoreconsole.exe to run AutoCAD from a service. We did replace the LISP code with custom .NET code (plugin), and as Augusto Goncalves suggested, we are using scripts to load the code and run it. – AntiTalent Jun 10 '18 at 07:44
0

It's Simple
A Windows service can't interact with the desktop and can't open programs with an interface.

Davide Pizzolato
  • 679
  • 8
  • 25