如何从C#程序启用Windows功能? [英] How Enable Windows Feature from C# Program?

查看:190
本文介绍了如何从C#程序启用Windows功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我有这样的问题。我的程序是用C#编写的,目标是.Net Framework 2.0版。现在我遇到了Windows 8操作系统的问题。我搜索了谷歌并发现,在Windows功能(在控制面板中)有一个复选框 - .Net Framework 3.5(包括.Net 2.0和3.0),当检查该复选框时,问题就解决了。现在,我必须在我的程序中使用什么C#代码,以便在我的程序打开时自动检查该框。



感谢您的帮助。



Romo

Hello everyone. I have such a problem. My program, written in C#, is targeting .Net Framework version 2.0 . And now I am having problems with Windows 8 OS. I searched through Google and found, that in Windows Features ( in Control Panel) there is a checkbox - .Net Framework 3.5 (includes .Net 2.0 and 3.0), when checking that check-box, the problem is solved. Now , what C# Code do I have to use in my program, for auto checking that box, when my program is opened.

Thanks for help.

Romo

推荐答案

你没有。不要修改用户的系​​统。您只需在文档中说明需求是什么,并由用户确保系统提供这些要求。
You don't. Do not modify a user's system. You simply state in the documentation what the requirments are and it's up to the user to ensure that the system provides those requirements.


如果您的.NET应用程序是针对特定版本的FrameWork编译的,并且在您的应用程序运行的机器上不存在/可用该版本,显然,您将无法运行您的应用程序。



这就是为什么许多安装过程提供了一些方法来提醒用户对某个版本的FrameWork(或FrameWork本身,如果不存在)的要求。例如,请参阅:[ ^ ]。



其他选择是:



1.如果没有FrameWork版本,那么你必须写一个非.NET程序,建议用户下载并安装FrameWork,然后启动你的应用程序。



自WinXP以来,Windows已附带一个版本的已安装FrameWork,但用户可能已从控制面板中删除。



2.如果存在某些版本的FrameWork,则可以为用户提供启动器应用程序根据您知道的版本编译,启动,测试是否存在所需的FrameWork版本,如果不存在,则建议用户安装等。



您可以找到一个不需要安装FrameWork的程序示例,并且测试是否存在.NET在CodeProject的一篇文章中:[ ^ ]。



并且,使用MS的ClickOnce安装过程检查;它会做正确的事情来安装所需的FrameWork版本。
If your .NET application is compiled against a certain version of the FrameWork, and that version is not present/available in the machine your application is run on, you will, obviously, not be able to run your application.

This is why many install processes provide some way to alert the user to the requirement for a certain version of the FrameWork (or the FrameWork itself, if not present). For example, see: [^].

The other alternatives are:

1. if no version of the FrameWork is present, then you'd have to write a non-.NET program that would advise the user to download and install the FrameWork, and then launch your Application.

Since WinXP, Windows has shipped with a version of the FrameWork installed, although the user might have removed (from the Control Panel).

2. if some version of the FrameWork is present, then you could provide the user a "launcher" application compiled against the version you know is present, that would start-up, test to see if the required version of the FrameWork is present, and, if not present, advise the user to install, etc.

You can find an example of a program that does not require the FrameWork is installed and that tests is .NET is present in an article here on CodeProject: [^].

And, check out using MS' ClickOnce install process; it will do the right thing to get the version of the FrameWork needed installed.


这篇关于如何从C#程序启用Windows功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆