Select to view content in your preferred language

Licensing ArcObjects Application While ArcGIS is Running

4199
5
Jump to solution
06-18-2010 07:33 AM
by Anonymous User
Not applicable
Original User: mdickie

I've written a piece for a standalone application that uses ArcObjects in c# to read shapefile attributes into a database.  My License initialization method works fine and can check out a license from our license server no problem.  The problem arrises when I open ArcGIS with an editor license, then run the stand alone app.  The stand alone application does not recognize that I currently have Editor open, and proceeds to run through the licensing, checking out another license.  Does anyone have an Idea of what I can do to check for currently licensed Applications, and use that license to run the stand alone application (as ArcGIS does when mulitple instances are launched).

        public ArcGISLicensing() {
            InitializeLicensing();
        }
        internal string InitializeLicensing() {

            initialize = new AoInitializeClass();
            esriLicenseStatus _stat;
            esriLicenseProductCode _code;

            try {
                _code = initialize.InitializedProduct();

            }
            catch(COMException _Exception) {
                if(_Exception.ErrorCode == -2147483638) {
                    _stat = initialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

                    if(_stat == esriLicenseStatus.esriLicenseNotLicensed) {
                        _stat = initialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
                        if(_stat == esriLicenseStatus.esriLicenseNotLicensed) {
                           _stat = initialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
                        }
                        if(_stat == esriLicenseStatus.esriLicenseNotLicensed) {
                            initialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
                        }
                    }

                    if(initialize.InitializedProduct() != esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB &&
                        initialize.InitializedProduct() != esriLicenseProductCode.esriLicenseProductCodeArcEditor &&
                        initialize.InitializedProduct() != esriLicenseProductCode.esriLicenseProductCodeArcView &&
                        initialize.InitializedProduct() != esriLicenseProductCode.esriLicenseProductCodeEngine) {
                        return "";
                    }

                }
            _code = initialize.InitializedProduct();
            }
            
            return _code.ToString();

        }
      
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: kirkktx

try using AppROT with IObjectFactory:



public static void ListLicences()
{
    IAppROT appRot = new AppROTClass();
    for (int i = 0; i < appRot.Count; i++)
    {
        IObjectFactory f = appRot.get_Item(i) as IObjectFactory;
        IAoInitialize aoInit=  f.Create("esriSystem.AoInitialize") as IAoInitialize;
        Debug.Print(aoInit.InitializedProduct().ToString());
        Marshal.FinalReleaseComObject(f);
    }
    Marshal.FinalReleaseComObject(appRot);
}

View solution in original post

0 Kudos
5 Replies
by Anonymous User
Not applicable
Original User: kirkktx

try using AppROT with IObjectFactory:



public static void ListLicences()
{
    IAppROT appRot = new AppROTClass();
    for (int i = 0; i < appRot.Count; i++)
    {
        IObjectFactory f = appRot.get_Item(i) as IObjectFactory;
        IAoInitialize aoInit=  f.Create("esriSystem.AoInitialize") as IAoInitialize;
        Debug.Print(aoInit.InitializedProduct().ToString());
        Marshal.FinalReleaseComObject(f);
    }
    Marshal.FinalReleaseComObject(appRot);
}
0 Kudos
by Anonymous User
Not applicable
Original User: mdickie

Thanks kirkktx,

I was able to solve the problem using needed using IAppRot and IObjectFactory as you suggested.
0 Kudos
by Anonymous User
Not applicable
Original User: mdickie

Thanks kirkktx,

I was able to solve the problem using needed using IAppRot and IObjectFactory as you suggested.


Well...
Not Quite.  I can get the IAOInitialize object, but ArcObjects Still isn't initialized.  I have a simple test case that shows this.  Do I have to do something with the IAOInitialize object?
0 Kudos
KirkKuykendall
Deactivated User
Even if some other desktop app is running, you still need to register the process you're running within via IAoInitialize.Initialize.  You only need to reference the IAoInitialize from the other process to determine the esriLicenseProductCode that it is running.  In most cases you could determine this using first word in IApplication.Caption, but this can be set programmatically, so is not completely reliable.

I'm guessing you want to write a standalone app that goes ahead and uses an expensive license if the user has a desktop app running at that license level.  Is this correct?

One floating license allows multiple apps to run on a machine for a particular license level.  For example, if your organization has floating seats of both ArcInfo and ArcEditor, it would make sense for a standalone app to initialize using ArcInfo if arcmap is already running with an ArcInfo license - it won't consume any more licenses.  OTOH, I'm pretty sure if arcmap is running with ArcInfo and then you initialize your standalone app with ArcEditor, you tie up an arceditor license unnecessarily.
0 Kudos
by Anonymous User
Not applicable
Original User: mdickie

You are right about me wanting my application to consume an ArcEditor License if they have it checked out already.  No Sense in checking out an ArcView, or ArcInfo at the same time. 

IAOInitialize will allow you to check out multiple licenses at different levels if you want but it seems to handle calls to checkout a license you have already checked out on its own.

As you suggested, all I had to do was initialize the IAOInitialize object using the license found through the IAppROT loop.

Thanks for Your Help.

for(int i = 0; i < _appRot.Count; i++) {
                        IObjectFactory _f = _appRot.get_Item(i) as IObjectFactory;
                        IAoInitialize _aoInit = _f.Create("esriSystem.AoInitialize") as IAoInitialize;
                        if(_aoInit != null) {
                            //Set IAOInitialize to the Initialized ArcGIS product.
                            //Need To Initialze ArcObjects Even Though ArcGIS is open.

                            _privateInit = _aoInit;
                            _privateInit = new AoInitializeClass();
                            _privateInit.Initialize(_aoInit.InitializedProduct());                     
                        }
0 Kudos