Marshal.GetActiveObject("Inventor.Application") fails

Marshal.GetActiveObject("Inventor.Application") fails

sandeep_vaal
Enthusiast Enthusiast
725 Views
1 Reply
Message 1 of 2

Marshal.GetActiveObject("Inventor.Application") fails

sandeep_vaal
Enthusiast
Enthusiast

We are facing strange issue when we are running Visual studio in non admin mode then its working perfect but same thing is not working in Admin mode. Can you please help us ?

 

Here is the code:

        /// <summary>
        /// Connects to a running instance of Inventor or
        /// Creates a new instance and connects to it.
        /// </summary>
        /// <returns>Instance of Inventor app</returns>
        private Inventor.Application Connect()
        {
            string InventorProgID = "Inventor.Application";
            Inventor.Application inventorApp = null;

            // Try to get an active instance of Inventor
            try
            {
                inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject(InventorProgID) as Inventor.Application;
                //This throws Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
            }
            catch
            {
                //(MK_E_UNAVAILABLE)) is expected when Inventor is not running in interactive mode.
            }

            // If Inventor is not running, create a new Inventor session
            if (null == inventorApp)
            {

                Type inventorAppType = Type.GetTypeFromProgID(InventorProgID); //This returns null, when process is Run As Administrator.
                Debug.Assert(inventorAppType != null, "inventorAppType is null.");

                if (null != inventorAppType)
                {
                    inventorApp = Activator.CreateInstance(inventorAppType) as Inventor.Application;
                    Debug.Assert(inventorApp != null, "inventorApp is null.");
                }
            }

            return inventorApp;
        }

 

This is what we observed in using process monitor.

 

[A] While running as Non-Admin User:

Process monitor shows successfull registry events as below.

 

ProcessMonitorInventorConnection-NonAdminMode.jpg

 

 

[B] While running as Admin User:

Process monitor shows unsuccessfull registry events as below.

 

ProcessMonitorInventorConnection-AdminMode.jpg

 

0 Likes
726 Views
1 Reply
Reply (1)
Message 2 of 2

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

I assume it boils down to the same porblem:

http://forums.autodesk.com/t5/inventor-customization/not-able-to-create-inventor-instance-when-visua...

 

Cheers, 



Adam Nagy
Autodesk Platform Services
0 Likes