Question

My application requires the windows feature

enter image description here

to be installed.

I currently use this solution to see if it is installed.

Now how will I be able to installe it once I know it is not running. I have tried:

List<ServiceController> services = ServiceController.GetServices( ).ToList( );
ServiceController msQue = services.Find( o => o.ServiceName == "MSMQ" );

if ( msQue != null )
{
    if ( msQue.Status == ServiceControllerStatus.Running )
    {
        Console.Write( "it is running" );
        return;
    }
}
else
{
    Console.WriteLine( "It is not running \n\nPress enter to install" );
    Console.Read( );
   msQue.Start( ); // <- I was hoping to look for a method that will turn feature on or off                          
}   
Was it helpful?

Solution

DISCLAIMER:

I wouldn't try to install it from code; instead, I would make Message Queueing a prerequisite of your application and install it when you install the app.


I don't know if you can do it from C# but here's articles on performing an unattended installation. You may be able to build a command line to perform the installation.

Server 2003 / Windows XP : http://technet.microsoft.com/en-us/library/cc778216(v=ws.10).aspx

Server 2008 / Windows 7: http://technet.microsoft.com/en-us/library/cc731283(v=ws.10).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top