7

Specifically, I'm working with an application that only runs on Server 2008 if the "Desktop Experience" feature is installed, and I'd like to have that application's installer verify it's there.

The only way I'm aware of currently is to run ServerManagerCmd -query and parse the output; I'd prefer something more lightweight (like checking a registry key).

2 Answers2

8

This is a code snippet of what I use to do it at runtime.

public static bool isServerFeatureInstalled(Win32_ServerFeature_ID id)
{
    bool idFound = false;
    ConnectionOptions connectionOptions = new ConnectionOptions();
    ManagementScope managementScope =
        new ManagementScope(
            @"\\localhost\root\cimv2", connectionOptions);

    ObjectQuery oQuery =
        new ObjectQuery("SELECT Id FROM Win32_ServerFeature");
    ManagementObjectSearcher oSearcher =
        new ManagementObjectSearcher(managementScope, oQuery);
    ManagementObjectCollection oReturnCollection = oSearcher.Get();

    foreach (ManagementObject oReturn in oReturnCollection)
    {
        if ((uint) (oReturn["ID"]) == (uint) id)
        {
            return true;
        }
    }
    return idFound;
}

// short list of names and values taken from MSDN. 
public enum Win32_ServerFeature_ID
{
    Application_Server = 1,
    Web_Server = 2,
    Media_Server = 3,
    Windows_Sharepoint_Services = 4,
    Fax_Server = 5,
    File_Services = 6,
    Print_Services = 7,
    Active_Directory_Federation_Services = 8,
    Active_Directory_Lightweight_Directory_Services = 9,
    Active_Directory_Domain_Services = 10,
    UDDI_Services = 11,
    DHCP_Server = 12,
    DNS_Server = 13,
    Network_Policy_and_Access_Services = 14,
    Certificate_Server = 16,
    Active_Directory_Rights_Management_Services = 17,
    Terminal_Services = 18,
    Windows_Deployment_Services = 19,
    Failover_Clustering = 33,
    Network_Load_Balancing = 34,
    Desktop_Experience = 35,
    DOTNET_Framework_30 = 36,
}
Jeff
  • 2,198
  • 3
  • 21
  • 38
  • This is very nice... and gets me half way on my problem (http://stackoverflow.com/questions/25573129/how-to-find-roles-on-a-server) How do you know if the machine has been promoted to a domain controller though? – MrLister Aug 29 '14 at 17:24
  • 1
    I tried your code and I am getting an "invalid class" exception on this 'foreach (ManagementObject oReturn in oReturnCollection)' -- any ideas? – MrLister Aug 29 '14 at 17:48
  • @user3174075 That is probably because you're running on a server version later than 2008 R2. The class has now been deprecated. – notbad.jpeg Jul 20 '16 at 15:42
0

On my testing Windows 2008 x64 std server running this command(adds the role):

ServerManagerCmd.exe -install AS-AppServer-Foundation 

adds this registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppServer

This command (removes the role):

ServerManagerCmd.exe -remove AS-AppServer-Foundation

removes the key. So I'd think it's a good enough of an indicator. These are just the results of my own research/experiment and is not an official/supported way of detecting if AppServer role is configured.

Zar Shardan
  • 5,675
  • 2
  • 39
  • 37