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(); }
Solved! Go to Solution.
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); }
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); }
Thanks kirkktx,
I was able to solve the problem using needed using IAppRot and IObjectFactory as you suggested.
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()); }