Windows 上的自更新 Exe par
我正在尝试创建一个脚本,当它在服务器上检测到新版本时,它将“自我更新”。最初我的想法是,当检测到新版本时,下载该文件,然后启动一个 DOS 批处理文件,该文件只需用新版本覆盖原始 exe。我想,我可以使用 sytem(start update.bat ) 然后立即退出 0; .bat 文件等待几秒钟,然后尝试删除旧的 exe。我想这失败了,因为即使使用 system(start ... ),新的“进程”实际上是同一个进程,这是正确的吗?有没有办法在 Windows 中从 perl 启动一个全新的进程,这将允许我删除 .exe?或者有其他更好的方法吗?
谢谢, 埃里克·塞弗特
I am trying to create a script that will "self update" when it detects a new version on a server. Initially the idea I had was, when a new version is detected, download the file, then starts a DOS batch file that simply overwrites the original exe with the new one. I thought, that I could use sytem(start update.bat ) then immediately exit 0; The .bat file waits for a couple seconds, and then tries to delete the old exe. This fails, I guess because even when using system(start ... ), the new "process" is actually the same process, is this correct? Is there any way to launch a completely new process from perl in windows, that would allow me to delete the .exe? Or is there a different approach that would be better?
Thanks,
Eric Seifert
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅 Windows 上的文档重新启动管理器,Windows Vista 中引入的 API,可以为您管理重新启动的应用程序以进行更新。
See the documentation on the Windows Restart Manager, an API introduced with Windows Vista that manages restarting applications, for updates, for you.
听说过 java WebStart 吗?有一个 PAR 等效项,PAR::WebStart
基本上,您配置它,然后从受信任的网站实时下载代码
,这样您的 .exe 将只是 PAR::WebStart 的前端,而真正的程序从您的网站下载
Ever heard of java WebStart? There is a PAR equivalent, PAR::WebStart
Basically, you configure it, then download code live from a trusted website
so your .exe would just be a frontend to PAR::WebStart, with the real program downloaded off your website
我知道这是一个老问题,但我想我应该把我的解决方案放在这里,因为我正在研究同样的事情。你的批处理想法是我的方式,但我所做的小改变是使用
exec()
而不是system()
自前者以来(根据 this) “...执行系统命令并且永远不会返回”,其中似乎释放了正在运行的进程。当使用 Strawberry Perl 运行解释的 Perl 文件时,以及使用PAR::Packer
运行编译的程序时,这似乎都有效。我创建了
test.pl
,它最终被编译为test.exe
,如下:testfile.exe
是一个备用的“升级版”test.exe
的版本,只是为了确保我可以在运行时覆盖test.exe
,而且我可以。ping
是一种暂停 2 秒的方法,以确保进程在尝试覆盖文件之前有机会退出。奇怪的是,创建的批处理文件
update.bat
无法删除自身,即使批处理文件通常可以删除自身。如果我用这个创建一个批处理文件:它将自行删除而不会出现任何错误。但是,如果我将该代码段包含在
update.bat
中,它会抱怨该进程无法访问该文件,因为它正在被另一个进程使用。
我不确定为什么。由于这在我的应用程序中并不是特别重要,因此我没有追求这一点。我只是留下update.bat
并让它在下次更新时被覆盖。但我没有在文件中注明,可以安全删除,以防以后有人查看它。I know this is an old question, but I thought I'd put my solution here since I'm working on the same sort of thing. Your batch idea is the way I went, but the small change I made was to use
exec()
instead ofsystem()
since the former (according to this) "...executes a system command and never returns", which seems to release the running process. This appears to work both when running interpreted Perl files with Strawberry Perl, and when running compiled programs withPAR::Packer
.I've created
test.pl
, which was ultimately compiled totest.exe
, as follows:testfile.exe
is a standby "upgraded" version oftest.exe
, just to make sure that I can overwritetest.exe
while it's running, and I can. Theping
is a way to pause for 2 seconds to make sure the process has had a chance to exit before trying to overwrite the file.Oddly enough, the created batch file
update.bat
can't delete itself, even though batch files can normally delete themselves. If I create a batch file with this:It will delete itself without any errors. But if I include that snippet in
update.bat
, it complains thatThe process cannot access the file because it is being used by another process.
I'm not sure why. Since this isn't particularly important in my application, I haven't pursued this. I just leaveupdate.bat
behind and let it be overwritten next time an update occurs. But I do notate in the file that it's safe to delete in case anyone looks at it later.