zoukankan      html  css  js  c++  java
  • WPF客户端实现.net升级

    客户端.net版本由3.5升级到4.5,首先把.net4.5的离线安装包添加到资源,程序运行的时候,从资源中生成离线安装包,并通过传递参数的方式执行静默安装命令,具体代码如下:

      

     1         private static void InstallDotNet()
     2         {
     3             Version vneed = new Version("4.5");
     4             bool needsetupdotnet = false;
     5             RegistryKey componentsKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full");
     6             if (componentsKey == null)
     7             {
     8                 needsetupdotnet = true;
     9             }
    10             else
    11             {
    12 
    13                 Version vcurrent = new Version(componentsKey.GetValue("Version").ToString());
    14                 if (vcurrent < vneed)
    15                 {
    16                     needsetupdotnet = true;
    17                 }
    18             }
    19             if (needsetupdotnet)//需要安装
    20             {
    21                 PropertyInfo dotnetpinfo = res.GetType().GetProperties(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance).Where(t => t.Name == "NDP452_KB2901907_x86_x64_AllOS_ENU").FirstOrDefault();
    22                 byte[] dotnetBytevalue = (byte[])dotnetpinfo.GetValue(res, null);
    23                 var dotnetfilePath = destpath + Path.DirectorySeparatorChar + "NDP452_KB2901907_x86_x64_AllOS_ENU.exe";
    24                 if (!Directory.Exists(Path.GetDirectoryName(dotnetfilePath)))
    25                 {
    26                     Directory.CreateDirectory(Path.GetDirectoryName(dotnetfilePath));
    27                 }
    28                 using (FileStream writer = new FileStream(dotnetfilePath, FileMode.OpenOrCreate))
    29                 {
    30                     writer.Write(dotnetBytevalue, 0, dotnetBytevalue.Length);
    31                 }
    32                 RunExe(dotnetfilePath, "", "/Q /NORESTART /lcid 1033");
    33             }
    34         }
    35 
    36         public static string RunExe(string filename, string strInput, string arguments)
    37         {
    38             Process p = new Process();
    39             //设置要启动的应用程序
    40             //p.StartInfo.FileName = "cmd";
    41             p.StartInfo.FileName = filename;
    42             //是否使用操作系统shell启动
    43             p.StartInfo.UseShellExecute = false;
    44             // 接受来自调用程序的输入信息
    45             p.StartInfo.RedirectStandardInput = true;
    46             //输出信息
    47             p.StartInfo.RedirectStandardOutput = true;
    48             //输出错误
    49             p.StartInfo.RedirectStandardError = true;
    50             //不显示程序窗口
    51             p.StartInfo.CreateNoWindow = true;
    52 
    53             if (!string.IsNullOrEmpty(arguments))
    54             {
    55                 p.StartInfo.Arguments = arguments;
    56             }
    57             //启动程序
    58             p.Start();
    59 
    60             //向窗口发送输入信息
    61             if (!string.IsNullOrEmpty(strInput))
    62             {
    63                 p.StandardInput.WriteLine(strInput + "&exit");
    64             }
    65             p.StandardInput.AutoFlush = true;
    66             //获取输出信息
    67             string strOuput = p.StandardOutput.ReadToEnd();
    68             //等待程序执行完退出进程
    69             p.WaitForExit();
    70             p.Close();
    71             return strOuput;
    72         }        
  • 相关阅读:
    RPI学习--环境搭建_更新firmware
    RPI学习--环境搭建_刷卡+wiringPi库安装
    [转]VS2005 Debug时提示"没有找到MSVCR80D.dll"的解决办法
    [转]结构体字节对齐
    [转]C++运算优先级列表
    putty基本操作
    Go 修改字符串中的字符(中文乱码)
    Go part 5 结构体,方法与接收器
    pickle 和 base64 模块的使用
    原来还有 卡夫卡 这个人存在
  • 原文地址:https://www.cnblogs.com/xienb/p/9304941.html
Copyright © 2011-2022 走看看