Ask a Jedi: Getting a list of application names in ColdFusion

This post is more than 2 years old.

Andy asks:

Is there a way to get a list of application names from all of the Application.cfc running on a server. I'm trying to dynamically build a server.applicationNameArray by just dropping a web app into the web tree. Thanks for your time.

Technically the answer to this is no, but there are two ways of doing this. The first way is to use the SeverMonitor API. There isn't a 'get a list of application names', but there is a method named getAllApplicationScopesMemoryUsed. This method returns the memory used by all application scopes on your server. The keys of the structure are your application names. Here is an example:

<cfset password = "poorspearsfamily"> <cfinvoke component="CFIDE.adminapi.administrator" method="login" adminpassword="#password#" returnVariable="result">

<cfinvoke component="CFIDE.adminapi.servermonitoring" method="getAllApplicationScopesMemoryUsed" returnVariable="ascopes"> <cfdump var="#ascopes#">

By the way, check out the memory usage for the model-glue app:

The Model-Glue app is the one in red. Model-Glue is so good it gives your server RAM. Yeah, that's it.

So the second solution is a bit of an hack, but has been around for a while. If you define an application w/o a name, the Application scope for that unnamed application will contain a bunch of junk, including a pointer to all the applications on your server. Consider this code:

<cfapplication> <cfloop item="k" collection="#application#"> <cfif isStruct(application[k]) and structKeyExists(application[k], "applicationname")> <cfdump var="#application[k]#" label="#k#"> </cfif> </cfloop>

This will dump each Application and all it's variables. Note the CFIF and how I check to see if the variable is an application scope. Not perfect, but in my test with both code blocks, it returned the same thing. (Well, the second code block didn't show the blank key for the unnamed application scope like the first one did.)

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Hemant posted on 12/20/2007 at 11:34 AM

I have logged a bug about the negative value and we will investigate.

Comment 2 by Anuj Gakhar posted on 12/20/2007 at 3:45 PM

Here is how I did it once.

Comment 3 by Raymond Camden posted on 12/20/2007 at 4:52 PM

Hermant - there should be a bug report already I think. It shows up in the Server Monitor as huge values, not big negative values.

Comment 4 (In reply to #2) by Paolo Broccardo posted on 7/4/2015 at 7:08 PM

Thanks - this was a much better solution for getting all applications and application names and resetting those applications programmatically!