Windows 上的自更新 Exe par

发布于 2024-11-08 14:13:01 字数 305 浏览 0 评论 0原文

我正在尝试创建一个脚本,当它在服务器上检测到新版本时,它将“自我更新”。最初我的想法是,当检测到新版本时,下载该文件,然后启动一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

Oo萌小芽oO 2024-11-15 14:13:01

请参阅 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.

尽揽少女心 2024-11-15 14:13:01

听说过 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

人生百味 2024-11-15 14:13:01

我知道这是一个老问题,但我想我应该把我的解决方案放在这里,因为我正在研究同样的事情。你的批处理想法是我的方式,但我所做的小改变是使用 exec() 而不是 system() 自前者以来(根据 this) “...执行系统命令并且永远不会返回”,其中似乎释放了正在运行的进程。当使用 Strawberry Perl 运行解释的 Perl 文件时,以及使用 PAR::Packer 运行编译的程序时,这似乎都有效。

我创建了test.pl,它最终被编译为test.exe,如下:

#!/usr/bin/perl

use 5.10.0;
use strict;
use warnings;

    my $batch_file = <<"BATCH";
rem ### IT IS SAFE TO DELETE THIS FILE ###

\@echo off
ping 127.0.0.1 -n 2 -w 1000 > nul
echo Copying over update file...
copy testfile.exe test.exe

BATCH

    open my $fh, '>', 'update.bat';
    print $fh $batch_file;
    close $fh;

    exec( 'update.bat' );

testfile.exe是一个备用的“升级版” test.exe 的版本,只是为了确保我可以在运行时覆盖 test.exe,而且我可以。 ping 是一种暂停 2 秒的方法,以确保进程在尝试覆盖文件之前有机会退出。

奇怪的是,创建的批处理文件 update.bat 无法删除自身,即使批处理文件通常可以删除自身。如果我用这个创建一个批处理文件:

start /b "" cmd /c del %0

它将自行删除而不会出现任何错误。但是,如果我将该代码段包含在 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 of system() 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 with PAR::Packer.

I've created test.pl, which was ultimately compiled to test.exe, as follows:

#!/usr/bin/perl

use 5.10.0;
use strict;
use warnings;

    my $batch_file = <<"BATCH";
rem ### IT IS SAFE TO DELETE THIS FILE ###

\@echo off
ping 127.0.0.1 -n 2 -w 1000 > nul
echo Copying over update file...
copy testfile.exe test.exe

BATCH

    open my $fh, '>', 'update.bat';
    print $fh $batch_file;
    close $fh;

    exec( 'update.bat' );

testfile.exe is a standby "upgraded" version of test.exe, just to make sure that I can overwrite test.exe while it's running, and I can. The ping 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:

start /b "" cmd /c del %0

It will delete itself without any errors. But if I include that snippet in update.bat, it complains that The 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 leave update.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文