2012-10-12 70 views
2

我的應用程序需要使用Windows功能安裝Windows消息隊列編程

enter image description here

安裝。

我目前使用this solution來查看它是否已安裝。

現在如果我知道它沒有運行,我將如何安裝它。我曾嘗試:

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       
} 
+1

有安裝,目前沒有運行,並且尚未安裝有很大的區別。如果尚未安裝,則不會打開/關閉。 MSMQ是一項可選的Windows功能,在Windows的默認安裝中完全不安裝。恐怕你唯一能做的就是讓用戶知道他們需要讓他們的IT人員安裝MSMQ來運行應用程序。如果它已安裝且當前未運行,則可以使用ServiceController類來啓動它。 – Kevin

回答

1

免責聲明

我不會嘗試從代碼安裝;相反,我會將消息隊列作爲應用程序的先決條件,並在安裝應用程序時安裝它。


我不知道您是否可以從C#這樣做,但這裏的一對執行無人蔘與安裝的文章。您可能能夠構建命令行來執行安裝。

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

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