简体   繁体   中英

How to enable Application Server role programmatically on Windows 2008 R2 and Windows 7

As part of an installation process I need to enable the Application Server role. I need to do this to get the distributed transaction features required by an application. I am able to do this easily on a Windows 2012 Server by executing dism.exe from a C# application. Here is the command that is executed.

dism /Online /Enable-Feature /FeatureName:Application-Server /FeatureName:AS-NET-Framework /FeatureName:AS-Ent-Services /FeatureName:AS-Dist-Transaction /FeatureName:AS-Incoming-Trans /FeatureName:AS-Outgoing-Trans

But when I try to do this on a Windows 2008 R2 Server or Windows 7 it fails indicating that DISM does not recognize these features. If I run the command on these machines to list the features (Get-Features) they indeed are not available. Even if I manually enable the Application Server role using the Role Manager and list the features available in DISM they are not listed or anything under a different name that would represent the Application Server Role.

How can I programmatically enable the Application Server Role on a Windows 2008 R2 Server and Windows 7 using C#? The solution does not have to use DISM. I am looking for any options.

So it turns out that even though Server Manager is depreciated on Windows 2008 R2 you can still use it to enable roles. Here is the command I used to enable it:

ServerManagerCmd -install Application-Server AS-Ent-Services AS-Dist-Transaction AS-Incoming-Trans AS-Outgoing-Trans

You will get the following warning but it works.

Servermanagercmd.exe is deprecated, and is not guaranteed to be supported in future releases of Windows. We recommend that you use the Windows PowerShell cmdlets that are available for Server Manager.

So how do you enable it on Window 7? You can't because it is a client operating system and these roles do not exist. But ultimately the reason for installing this role was to get distributed transactions installed and configured. Turns out on Windows 7 that the Distribute Transaction Coordinator is already available and you just have to configure it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM