Posts: 13
Registered: ‎04-17-2012
Message 1 of 4 (496 Views)
Accepted Solution

Closing AutoCAD from VB.NET

496 Views, 3 Replies
01-31-2014 12:22 PM

I am using VB.NET 2010 and AutoCAD OEM 2014 (though for Development I use regular AutoCAD 2014).  I run Visual Studio, and it opens AutoCAD automatically.  Then I NETLOAD my app, which opens a new vb.net form.  Then my user can draw different entitites onto the AutoCAD pallette.


Of course it's easy to close the VB form, but how can I close the full AutoCAD program programatically from my VB form?  I've tried AcadApp.Quit() from my VB form but it does nothing.


The reason that this is important not to leave it to the user to close it is that I check for a valid license from VB, and if there is none, I don't want the user to be able to continue to use AutoCAD.


Also, what/where is the reference manual to find examples of using VB.NET and AutoCAD?


thanks in advance!


Oil Industry
*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (468 Views)

Re: Closing AutoCAD from VB.NET

02-01-2014 03:14 AM in reply to: BugWare
Handle Form_Closing event either for modal or modeless form:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
Valued Contributor
Posts: 86
Registered: ‎09-05-2012
Message 3 of 4 (459 Views)

Re: Closing AutoCAD from VB.NET

02-01-2014 06:43 AM in reply to: Hallex
That will probably work 99% of the time except if autocad is stuck on some command. I think Environment.Exit(0) will "brute force" close it no matter what.
Posts: 13
Registered: ‎04-17-2012
Message 4 of 4 (327 Views)

Re: Closing AutoCAD from VB.NET

02-20-2014 06:29 AM in reply to: BugWare

Environment.Exit(0)  seems to work nicely, and I like the 'brute force' approach since the user no longer has valid use of the program if it reaches this point.  Thanks very much!

Oil Industry
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.