Auto Updating the exe from a network location when application starts z

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

时间: 2024-10-06 05:35:02

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

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

在安装控件过程中出现提示Error 1606 Could Not Access Network Location %SystemDrive%/inetpub/wwwroot/ 的错误解决方法 1. 点击开始菜单    –运行  –regedit   后按回车键 2,找到注册表   HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/InetStp/PathWWWRoot  (32位系统) 或者  HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Nod

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'原因就是格式没有对齐导致的

导致报错原因就是格式问题,对齐就好了,百度竟然说编码导致的,郁闷 "C:\Program Files\Java\jdk1.8.0_101\bin\java" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=63341 -Dcom.sun.management.jm

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

在卸载或者重安装Infragistics NetAdvantage时候提示如标题的错误 win7下 1.打开注册表 Regedit 2.找到HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/InetStp/PathWWWRoot 64位操作系统:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\InetStp\PathWWWRoot %SystemDrive%/inetpub/wwwroot/ ==> C:\inetpu

Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />

<context:property-placeholder location="classpath*:*.properties" ignore-unresolvable="true"/> 1.有些参数在某些阶段中是常量 比如:a.在开发阶段我们连接数据库时的连接url,username,password,driverClass等 b.分布式应用中client端访问server端所用的server地址,port,service等 c.配置文件的位置 2.而

NXP ARM Vector Table CheckSum

Signature Creator for NXP Cortex-M Devices Algorithm for creating the checksum The reserved Cortex-M3 exception vector location 7 (offset 0x001C in the vector table) should contain the 2’s complement of the check-sum of table entries 0 through 6. Thi

How Network Load Balancing Technology Works--reference

http://technet.microsoft.com/en-us/library/cc756878(v=ws.10).aspx In this section Network Load Balancing Terms and Definitions Network Load Balancing Architecture Network Load Balancing Protocols Application Compatibility with Network Load Balancing

IOCP大并发svchost.exe(NlaSvc服务)占满CPU问题分析

症状: 使用IOCP开发的SSLSpider(SSL证书扫描服务)运行一会后(4000并发),系统的一个svchost.exe一直满一个CPU内核(共4核). 分析: 此进程运行了4个服务: 停止WinRM.Dnscache都没用,停止NlaSvc超时了,应该是这货在作怪,Google... 真的是它! 「别人遇到的,貌似没找到解决方法 http://www.tomshardware.com/forum/302313-28-usage-minutes-turned-urgent」 暂时先停掉这个

Auto Layout Guide----(一)-----Understanding Auto Layout

Understanding Auto Layout 理解自动布局 Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views. For example, you can constrain a button so that it is horizontally centered

Android官方文档之Location and Sensors APIs(上)

定位(Location) 和 传感器(Sensors)API充分发挥了移动设备的优势,您可以调用这些API,制作出交互性较高的应用程序,比如使用设备自带的GPS模块定位.或使用网络定位:使用加速器模块(accelerometer)监听设备的加速度.陀螺仪模块(gyroscope)监听设备偏转/倾斜时的转动角速度.温度计模块(temperature)测量当前设备所处环境的温度.气压计模块(barometer)测量当前设备所处环境的气压 等. 本文将介绍Android中地理定位的技术要点.在下一篇文