重新启动Powershell脚本(如果关闭)?

时间:2019-11-30 04:07:27

标签: powershell batch-file

计算机启动时,我将使用bat文件启动Powershell脚本。但是,如果有人将其关闭或崩溃,我需要重新启动它。

到目前为止,我使用以下命令调用脚本:

q = Parent.objects.annotate(num_child=Count('child', distinct=True), num_grand_child=Count('child__grandchild', distinct=True))

但是关闭后如何重新启动?

谢谢!

1 个答案:

答案 0 :(得分:0)

Windows 10 64位。 Powershell 5

将所有这些操作从Windows启动文件夹移动到登录时运行的hidden /后台/非交互式计划任务中。

在地标文件退出之前,使用unbilling.ps1create

New-Item -Path $env:temp -Name "UnbillingPs1Finished.txt" -ItemType File -force
exit 

在批处理测试中,如果文本文件存在并且不运行,则unbilling.ps1

:loop
if not exist %temp%\UnbillingPs1Finished.txt (
powershell.exe -window minimized -noexit -file "%USERPROFILE%\Desktop\UNB\script\UNBILLING.ps1"
goto :loop
)
del %temp%\UnbillingPs1Finished.txt