博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Auto Updating the exe from a network location when application starts z
阅读量:5843 次
发布时间:2019-06-18

本文共 1758 字,大约阅读时间需要 5 分钟。

http://www.codeproject.com/Tips/869588/Auto-Updating-the-exe-from-a-network-location-when?msg=4992189#xx4992189xx

 

Using the code

I wrote a simple console application in c# to accomplish this task

In the Program.cs itself I wrote the code to check updates and then executed the updated application

using System.Collections.Generic;using System.Diagnostics;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks; namespace ShipitIntro { class Program { static void Main(string[] args) { //updatepath is the location where I upload updated exe string UpdatePath = @"\\testserver\Art\ship it\Shipit.exe"; //applocation is the location from where this console app runs.It will also be the location where the new file will be saved string AppLocation = Directory.GetCurrentDirectory() + @"\shipit.exe"; try { FileInfo info1 = null; FileInfo info2 = null; if (File.Exists(UpdatePath)) { //If there is a file in the update location info1 will get the fileinfo of that file info1 = new FileInfo(UpdatePath); } if (File.Exists(AppLocation)) { //if the exe is already present in the aplocation get its information also info2 = new FileInfo(AppLocation); } else { File.Copy(UpdatePath, AppLocation, true); ExecuteApp(AppLocation); return; } if (info1.LastWriteTime > info2.LastWriteTime) { File.Copy(UpdatePath, AppLocation, true); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } ExecuteApp(AppLocation); } static void ExecuteApp(string location) { if (File.Exists(location)) { try { Process.Start(location); } catch (Exception ex) { Debug.WriteLine(ex.Message); return; } } else { } } } }

 The  function executeApp() will help in starting the exe from the location .thus it makes sure that the user always use the latest exe

 
 
 

转载地址:http://gfqcx.baihongyu.com/

你可能感兴趣的文章
解密javascript模块载入器require.js
查看>>
markdown 书写代码
查看>>
逆天通用水印扩展篇~新增剪贴板系列的功能和手动配置,卸除原基础不常用的功能...
查看>>
【转】彻底理解安卓里的ldpi、mdpi、hdpi、xhdpi、xxhdpi文件夹含义
查看>>
Java用WebSocket + tail命令实现Web实时日志
查看>>
vim for python
查看>>
国外某牛人的JsonModelBinder 实现 MVC 3.0
查看>>
Codeforces Round #395 (Div. 2)(A.思维,B,水)
查看>>
Enum
查看>>
hibernate 入门案例
查看>>
UISearchBar 点击取消回到原来位置时会跳动的解决方法
查看>>
【重新挂载磁盘空间】Linux系统/home的磁盘空间重新挂载给/root
查看>>
质控工具之TrimGalore使用方法
查看>>
Perl中的执行上下文
查看>>
docker 批量删除容器和镜像
查看>>
[linux] 查看目录/文件字节数
查看>>
servlet过滤器
查看>>
js 金额文本框实现代码
查看>>
js 兼容添加事件响应函数
查看>>
IP Failover Setup using Keepalived on CentOS/Redhat 6
查看>>