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

Collapse | Copy Code
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

 
 
 

Auto Updating the exe from a network location when application starts z的更多相关文章

  1. win7 、2008 提示Error 1606 Could Not Access Network Location %SystemDrive%/inetpub/wwwroot/ 的错误解决方法

    在安装控件过程中出现提示Error 1606 Could Not Access Network Location %SystemDrive%/inetpub/wwwroot/ 的错误解决方法 1. 点 ...

  2. java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'

    java.lang.IllegalStateException: Failed to load property source from location 'classpath:/applicatio ...

  3. Eureka启动报错:Failed to load property source from location 'classpath:/application.yml'

    原因: 将application.yml添加到classpath时, 由于变更了application.yml的编码格式(或许也改变了些代码内容), 而target内的yml文件没有实时更新, 从而导 ...

  4. Error 1606 Could Not Access Network Location %SystemDrive%/inetpub/wwwroot/ 的错误解决方法

    在卸载或者重安装Infragistics NetAdvantage时候提示如标题的错误 win7下 1.打开注册表 Regedit 2.找到HKEY_LOCAL_MACHINE/SOFTWARE/Mi ...

  5. 安装、卸载 node.js出错 Could not access network location *:\node.js\ 出错

    上周五,WIN10自动更新系统,导致我的node.js 和 Gradle 还有解压的winRAR都不能用!!!可恶 自动更新!!可恶啊!!! 然后我想把node.js重新卸载了再安装,结果 很慌很慌, ...

  6. 排错技能:任务管理器中追踪某w3wp.exe是哪个IIS站点的application pool

    如果Windows的任务管理器中发现某个w3wp.exe占用了100%CPU,那我们就要揪出这是那个网站的application pool在作怪, 首先,每个站点一定要单独使用各自的applicati ...

  7. springboot启动报异常,Failed to load property source from location 'classpath:/application.yml'

    学习springboot,在启动时抛出下图异常 往下看异常信息,找到异常的具体位置 找到application.yml文件的对应位置,发现params配置前面多了空格 去掉空格重新启动,可以了 写代码 ...

  8. Springboot - java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'

    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key in 'reader', lin ...

  9. Win7系统服务优化完全攻略

      前文提到Windows系统启动的原理,其中加载各项系统服务是影响系统启动时间的重要因素,之前软媒在Win7之家(http://www.win7china.com/)和Vista之家(http:// ...

随机推荐

  1. Bootstrap的clearfix

    1.div的内容太多会导致后面的div错位 <!DOCTYPE html> <html> <head> <title>自定义占满wgnu</tit ...

  2. Oracle临时表(Temporary Table)

    GLOBAL TEMPORARY代表全局临时表临时表的元数据存储在数据字典里面 只当第一条DML命令发生的时候才为这张表的段分配空间 临时表数据的可见范围应该是会话级别或是事务级别的 会话或者事务级别 ...

  3. Java 数据结构之Stack

    Stack类表示后进先出(LIFO)的对象堆栈.栈是一种非常常见的数据结构.Stack继承Vector,并对其进行了扩展. 用法: 1.只有一个构造函数: public Stack() {} 2.创建 ...

  4. google protobuf使用

    下载的是github上的:https://github.com/google/protobuf If you get the source from github, you need to gener ...

  5. USACO Section 3.2: Factorials

    这题注意要保存%10000的数. /* ID: yingzho1 LANG: C++ TASK: fact4 */ #include <iostream> #include <fst ...

  6. Android 调试机制

    Android的调试信息可以根据DDMS进行查看,Logcat日志输出所有的调试信息,为了方便的找到我们需要的打印信息,可以在logcat后面增加过滤器.比如你想查看system.out.printl ...

  7. c#操作txt

    C#追加文件 StreamWriter sw = File.AppendText(Server.MapPath(".")+"\\myText.txt"); sw ...

  8. datetimepicker文件

    很有诚意先放下载地址百度网盘 最近在做angular的项目,找一个合适的 datepicker ,首选bootstrap-datetimepicker,但是项目中没有到bootstrap, 整理处理下 ...

  9. django中post方法和get方法的不同

    当我们提交表单仅仅需要获取数据时就可以用GET: 而当我们提交表单时需要更改服务器数据的状态,或者说发送e-mail,或者其他不仅仅是获取并显示数据的时候就使用POST. 在这个搜索书籍的例子里,我们 ...

  10. hibernate学习笔记6--Criteria查询方式、完整小练习(开发步骤)

    一.Criteria查询方式没有sql语了,因此更加面向对象一些.Criteria是一种比HQL更面向对象的查询方式:Criteria的创建方式: Criteria c = s.createCrite ...