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.
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.
It's Simple
A Windows service can't interact with the desktop and can't open programs with an interface.
User contributions licensed under CC BY-SA 3.0