2

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                          
}   
Community
  • 1
  • 1
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
  • 1
    There is a big difference between installed and not currently running and not yet installed. If it is not yet installed, there is no on/off. MSMQ is an optional Windows feature that is not installed at all in the default installation of Windows. I'm afraid the only thing you will be able to do is to let the user know that they need to have their IT people install MSMQ for the application to run. If it is installed and not currently running you can use the ServiceController class to start it. – Kevin Oct 12 '12 at 16:07

1 Answers1

1

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

D Stanley
  • 149,601
  • 11
  • 178
  • 240