程序安装时检查是否已经安装.NETFramework

添加新项中添加一个安装程序类
None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Configuration.Install;
None.gif
using  Microsoft.Win32;
None.gif
using  System.Diagnostics;
None.gif
using  System.IO;
None.gif
namespace  DOTNETCheck
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// CheckDotnet 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [RunInstaller(true)]
InBlock.gif    
public class CheckDotnet : System.Configuration.Install.Installer
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 必需的设计器变量。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private System.ComponentModel.Container components = null;
InBlock.gif
InBlock.gif        
public CheckDotnet()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 该调用是设计器所必需的。
InBlock.gif
            InitializeComponent();
InBlock.gif
InBlock.gif            
// TODO: 在 InitComponent 调用后添加任何初始化
InBlock.gif
            
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Component Designer generated code#region Component Designer generated code
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            components 
= new System.ComponentModel.Container();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
public override void Install(System.Collections.IDictionary stateSaver)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif        
InBlock.gif            
//入口
InBlock.gif
            RegistryKey key=null;
InBlock.gif            key 
= Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\.NETFramework\\policy\\v1.0");
InBlock.gif            
if(key==null||key.GetValue("3705")==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                    Process MyProcess
=new Process(); 
InBlock.gif                    MyProcess.StartInfo.FileName
="dotnetfx.exe";
InBlock.gif                    MyProcess.StartInfo.WindowStyle
=ProcessWindowStyle.Hidden;
InBlock.gif                    MyProcess.Start();
InBlock.gif                    MyProcess.WaitForExit(); 
//等待程序执行
InBlock.gif
                    MyProcess.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值