我在网络驱动器上有一个简单的 c# 可执行文件,每天都会更新,但如果人们让它在计算机上运行/打开,则无法更新
使人们可以在本地运行它而不是指向网络驱动器的快捷方式的最简单方法是什么?
我想让他们总是在本地运行它,并让它在启动时检查更新,也许创建一个文本文档(在带有可执行文件的网络驱动器上),其中包含我随每个版本更新的最新版本号,它读取它在应用程序启动时进行流读取,如果最新版本号大于正在运行的可执行文件,它会提示消息对话框,并要求更新到最新版本,如果是,它会将其从网络驱动器复制...我不知道如何让它在应用程序运行时复制最新版本并覆盖自身,而不需要制作单独的可执行文件......我只是想保持它非常简单,我觉得必须有一种方法。
在一次失败的尝试中,我创建了一个文件监视来监视网络驱动器的目录,当插入文件名为“终止”的文件时,它将关闭所有正在运行的计算机上的程序实例,并让我更新该文件:) ...然而,网络安全不允许此功能运行,并且除非该程序在本地运行,否则它会在启动时出错,这会删除允许人们在桌面上保留指向该文件的快捷方式的全部目的。
编辑,目前我认为拥有一个计时器并让它在每晚 7:00 PM 关闭会很有趣。此后的任何时间都是我 90% 的时间都在工作的时候。
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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其移植到人们的计算机上的最简单方法可能是 xcopy 部署和使用登录脚本创建的快捷方式?这将是一项网络管理任务。
或者,ClickOnce部署它。这将托管在网页中并处理应用程序更新。它也很容易安装。
正如你所说,它将无法自行更新,该进程将锁定文件。如果您选择手动执行此操作,您将需要一个代理可执行文件来处理更新。 Paint.NET 在更新自身时会执行此操作。
对于用户来说,这个 exe 的存在可以保持沉默 - 您可以将其作为主 exe 的资源并仅在更新期间将其写入文件。更新后,更新exe可能会再次被主exe删除。
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.
我认为您可能想要部署一个应用程序,将可执行文件的“最新”版本复制到本地计算机,然后在本地启动它。
所以基本上是一小批
让他们在本地计算机上运行该文件,而不是从网络驱动器运行 exe。
您只需更新网络驱动器即可。下次运行该应用程序时,它将获取最新版本,然后在本地运行它。
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
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.