批处理脚本无法正常工作

发布于 2025-01-08 04:40:33 字数 736 浏览 0 评论 0原文

我编写了一个脚本来删除执行 exe 文件后创建的批处理文件,该批处理文件是用快速 bfc 编译的,因为它不会自行执行此操作,一旦进程不存在,就会包含源代码。问题是它删除了它的自身并结束了两个进程,它的自身和xxx.exe。我的目标是让它每 2 秒检查一次该进程是否存在的循环。如果该进程不再运行,它将删除 %temp% 文件夹中启用该进程的任何可能文件的 h 属性,然后删除 %temp% 文件夹中的所有内容。如果存在,它会再次执行相同的过程来检查 xxx.exe 是否存在。

@echo off
start xxx.exe
:A
tasklist 2>nul | find "xxx.exe" 1>nul
if  not ErrorLevel 1 (
echo Wscript.Sleep 2000> %temp%\sleep.vbs
start /w wscript.exe %temp%\sleep.vbs
del %temp%\sleep.vbs /f /q
goto A
) else (
Goto B
)
:B
attrib -h %temp%\*.*
del %temp%\*.* /f /q
exit

附注 添加了 goto B 部分,因为第一次成功尝试也没有成功。 请记住,当 xxx.exe 启动时,它使用在 %temp% 文件夹中创建的批处理文件,因此如果 xxx.exe 终止,它仍然能够运行,从而仅使 cmd.exe 处于活动状态。 用于检查进程是否存在的脚本显然是不可见的。 启动的批处理文件提供菜单,例如 1.Do xxx 2. sddd 。

I've written a script to delete the batch file created once the exe file is executed which was compiled with quick bfc since it doesn't do it by its self, containing the source code once process is non-existent. The problem is that it deletes it's self and ends two processes, its self and xxx.exe. My aim is for it to go through a loop of checking every 2 seconds whether the process exists or not. If the process is no longer running, it removes the h attribute of any of the possible files that it is enabled on in the %temp% folder and then it delete everything in the %temp% folder. If it does it goes through the same process again of checking whether xxx.exe exists or not.

@echo off
start xxx.exe
:A
tasklist 2>nul | find "xxx.exe" 1>nul
if  not ErrorLevel 1 (
echo Wscript.Sleep 2000> %temp%\sleep.vbs
start /w wscript.exe %temp%\sleep.vbs
del %temp%\sleep.vbs /f /q
goto A
) else (
Goto B
)
:B
attrib -h %temp%\*.*
del %temp%\*.* /f /q
exit

p.s
Added the goto B part since the first attempt for success didn't work either.
Keep in mind, when xxx.exe is launched it uses the batch file created in the %temp% folder so if xxx.exe is terminated it will still be able to function thus leaving only cmd.exe active.
The script used to check whether the process exists or not is obviously invisible.
The batch file launched offers menu's e.g 1. Do xxx
2. sddd
.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

善良天后 2025-01-15 04:40:33

混合使用 VBScript 和批处理脚本似乎有点奇怪,因为您无法使用一种技术有效地解决问题。也许,如果您将整个解决方案迁移到 VBScript,您将拥有一个更优雅的解决方案。

 Option Explicit
 Const WS_SHOW = 1
 Dim objShell
 Set objShell = CreateObject("WScript.Shell")
 objShell.Run "xxx.exe", WS_SHOW, True
 Dim objFSO
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 objFSO.DeleteFile "xxx.exe"

Seems a bit odd to mix VBScript and batch scripting since you're not effectively solving the problem in one technology. Perhaps, if you migrated your entire solution to VBScript you would have a more elegant solution.

 Option Explicit
 Const WS_SHOW = 1
 Dim objShell
 Set objShell = CreateObject("WScript.Shell")
 objShell.Run "xxx.exe", WS_SHOW, True
 Dim objFSO
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 objFSO.DeleteFile "xxx.exe"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文