【问题标题】:How Do I delete .hta file after some seconds in bat files [closed]如何在 bat 文件中几秒钟后删除 .hta 文件 [关闭]
【发布时间】:2021-05-08 06:28:07
【问题描述】:

我有这个代码:

@echo off
@title Login
echo ^<htm^> >> "start.hta"
echo ^<head^> >> "start.hta"
echo ^<link rel="stylesheet" link="style.css"^> >> "start.hta"
echo ^</head^> >> "start.hta"
echo ^<body^> >> "start.hta"
echo ^<p^>Hello!^</p^> >> "start.hta"
echo ^</body^> >> "start.hta"
echo ^</html^> >> "start.hta"
start.hta

但是,我想在 10 秒结束时删除“start.hta”并关闭窗口。 我该怎么做?

【问题讨论】:

  • 我看不出有任何理由从批处理文件中编写您的 HTA,尤其是所有需要的转义,或者不直接从 HTA 本身中关闭它. Here's a quick example 向您展示一个更简单的方法!

标签: html batch-file hta


【解决方案1】:

通过合并一些powershell获取进程ID,休眠10秒并通过进程ID杀死。

@echo off
@title Login
echo ^<htm^> > "start.hta"
echo ^<head^> >> "start.hta"
echo ^<link rel="stylesheet" link="style.css"^> >> "start.hta"
echo ^</head^> >> "start.hta"
echo ^<body^> >> "start.hta"
echo ^<p^>Hello!^</p^> >> "start.hta"
echo ^</body^> >> "start.hta"
echo ^</html^> >> "start.hta"
for /f %%i in ('powershell "(Start-Process start.hta -passthru).ID"') do (
    timeout /t 10
    taskkill /F /PID %%i
    del "start.hta"
)

【讨论】:

  • 这是工作!谢谢。
猜你喜欢
  • 2023-01-20
  • 1970-01-01
  • 2022-10-06
  • 2014-12-24
  • 1970-01-01
  • 1970-01-01
  • 2019-03-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多