开发者

I have a simple c# executable on a network drive that I update daily, but can't if people leave it running/open on their machine

开发者 https://www.devze.com 2023-02-16 21:11 出处:网络
What is the easiest way to make it so people can run it locally instead of a shortcut pointing to the network drive?

What is the easiest way to make it so people can run it locally instead of a shortcut pointing to the network drive?

I figure have them run it locally always, and have it check for updates on startup, maybe create a text document (on the network drive w/ the executable) with the latest version number in it that I update with each version, and it reads it w/ streamread on application startup, and if the latest version number was greater than the executable running, it would prompt a message dialogue, and ask to update to latest version and if yes, it would copy it off the network drive...I am not sure how to make it copy the latest version and overwrite itself while the application is running, without making a separate executable...I just want to keep it very simple and I feel like there must be a way.

In a failed attampt, I created a filewatch that monitored the directory of the network drive, and when a file was inserted w/ the file name "terminate" it would close the instance of the program on all running machines and let me update the file :) ...Network security however would not allow this function to run, and it开发者_运维问答 would get an error on startup unless the program was run locally, which deletes the whole purpose of allowing people to keep a shortcut on their desktop pointing to the file.

Edit, for now I thought it would be fun to have a timer and have it shutdown every night at 7:00 PM. Any time after that is when I work on it 90% of the time.

private void Form1_Load(object sender, EventArgs e)
        {
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.timer1.Interval = 30000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

            this.timer1.Start();

        }
        private void timer1_Tick(object sender, System.EventArgs e)
        {



            DateTime t1 = Convert.ToDateTime(DateTime.Now.ToShortTimeString());

            DateTime t2 = Convert.ToDateTime(("7:00 PM"));
            if (t1.TimeOfDay.Ticks == t2.TimeOfDay.Ticks)

            {
                this.Close();
               // /DateTime.Now.ToShortTimeString();
            }


The easiest way to get this onto people's machines is potentially an xcopy deployment and a shortcut created using a log-in script? This would be a network admin task.

Alternatively, ClickOnce deploy it. This will be hosted in a web page and handles application updates. It's also easy to install.

It will not be able to update itself, as you say, the process will lock the file. If you choose to do this manually, you will need a surrogate executable to handle the update. Paint.NET does this when it updates itself.

To the user, the existence of this exe can be kept silent - you could hold it as a resource of the main exe and write it out to file only during updates. After an update, the update exe could be deleted by the main exe again.


I would think you might want to deploy an application that copies the "latest" version of the executable to the local machine and then launches it locally.

so basically a little batch

cp <path/to/remote> <path/to/local>
<path/to/local>

Have them run that one their local machines rather than running the exe from the network drive.

You will simply have to update the network drive. The next time they run the app, it'll get the latest version and then locally run it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号