Shutting down COM app from a command line

L

Larry Bud

Not sure where else to post this.... One of our developers quit and
I'm taking over stuff from him.

He had a COM app that would lock files on occasion (yeah, thanks for
leaving that in production instead of finding the real problem)...
anyway, the "fix" was to shut down the com app when it would lock the
file.

Any way to do that from a command line?
 
E

Eric

using System;
using System.Collections;
using System.Collections.Specialized;
using COMAdmin; // This needs a reference to the "COM+ Admin" dll on
the COM tab

namespace xxx
{
class ShutdownCom
{
#region Get COM+ Applications
public StringCollection GetCOMApplications()
{
StringCollection collection = new StringCollection();
try
{
ICOMAdminCatalog objAdmin;
ICatalogCollection objCollection;

objAdmin = (ICOMAdminCatalog) new
COMAdmin.COMAdminCatalog();
objCollection = (ICatalogCollection)
objAdmin.GetCollection("Applications");
objCollection.Populate();

foreach(COMAdmin.COMAdminCatalogObject objApp in
objCollection)
{
collection.Add(objApp.Name.ToString());
// Console.WriteLine(objApp.Name.ToString());
}
}
catch(Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
return null;
}
return collection;
}
#endregion

#region Shutting Down COM+ Application
public void ShutDownCOMApplication(string appName)
{
try
{
ICOMAdminCatalog objAdmin;
ICatalogCollection objCollection;

objAdmin = (ICOMAdminCatalog) new
COMAdmin.COMAdminCatalog();
objCollection = (ICatalogCollection)
objAdmin.GetCollection("Applications");

Console.WriteLine("Shutting down: " + appName);
objAdmin.ShutdownApplication(appName);
}
catch(Exception ex)
{
Console.WriteLine("Unable to shutdown the application, err=" +
ex.Message);
}
}
#endregion


[STAThread]
static void Main(string[] args)
{
// create an instance of our class
ShutdownCom shutdown = new ShutdownCom();

// shutdown all applications that begin with ZC
StringCollection appList = shutdown.GetCOMApplications();
foreach (string appName in appList)
{
if (appName.ToUpper().StartsWith("ZC"))
shutdown.ShutDownCOMApplication(appName);
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top