How can you programmatically turn off or on 'Windows Features'

匆匆过客 提交于 2019-12-19 06:03:31

问题


Currently, users must go into Control Panel > Programs > Turn Windows features on or off, then click on the check the box of the feature that they want to activate. I'd like to give them the ability to do this from my application.

Any idea on how to automate this process via .NET (preferably in C#)?


回答1:


I do this using NSIS for IIS using :

$Sysdir\pkgmgr.exe /n:$Temp\iis7Unattend.xml

You can call the pkgmgr program from your c# program and usually you would create an unattend file with the instructions for the pkgmgr to use for the feature.

You need to use

 System.Diagnostics.Process.Start().



回答2:


If you are only targeting newer platforms (>= Windows Vista) then dism.exe is the latest utility; it replaces pkgmgr.

  1. http://technet.microsoft.com/en-us/library/dd799309(WS.10).aspx
  2. http://msdn.microsoft.com/en-us/library/dd371719(v=vs.85).aspx

Example call (run for all required features):

dism.exe /online /enable-feature /featurename:IIS-WebServerRole

To find a feature, use this

dism.exe /online /get-features | find “Tablet”

see: http://adriank.org/microsoft-ocsetupdism-component-name-list/ for more info.



来源:https://stackoverflow.com/questions/8054282/how-can-you-programmatically-turn-off-or-on-windows-features

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!