Not able to create inventor instance when Visual studio in Admin mode

Not able to create inventor instance when Visual studio in Admin mode

sandeep_vaal
Enthusiast Enthusiast
2,042 Views
1 Reply
Message 1 of 2

Not able to create inventor instance when Visual studio in Admin mode

sandeep_vaal
Enthusiast
Enthusiast

Hello,

 

I am getting strange problem when I am trying to create instance of inventor application it is giving me exception when Visual studio is in Admin and If I run same thing in non admin mode then it works fine.

 

Anybody know what is the problem here ? Please refer below code.

 

Thanks,

Dinesh

dinesh.gavsane@vaal-triangle.com

 

 

 static 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;
            }
            catch
            {

            }

            // If not active, create a new Inventor session
            if (null == inventorApp)
            {
                Type inventorAppType = Type.GetTypeFromProgID(InventorProgID); // giving exception in Admin mode

                if (null != inventorAppType)
                {
                    inventorApp = (Inventor.Application)System.Activator.CreateInstance(inventorAppType) as Inventor.Application;
                    if (null != inventorApp)
                    {
                        // set the flag to indicate we started the Inventor app so we shall quit it.
                        
                    }
                }
            }

            return inventorApp;
        }

0 Likes
2,043 Views
1 Reply
Reply (1)
Message 2 of 2

YuhanZhang
Autodesk
Autodesk

Hi Sandeep,

 

Here the link explains from Microsoft about the reason why it fails to call the COM interface:

 

https://msdn.microsoft.com/en-us/library/bb756926.aspx

 

 

If you have UAC on, and your application requests administrator privilege to run, then it can not access the registry of HKEY_CURRENT_USER, and Inventor has some registry values in HKEY_CURRENT_USER for the CreateInstance to work, so your application would fail in this case, and if you run it as standard user privilege it would work. So I suggest in this case you just run your application in standard user privilege.

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.