Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 我需要帮助编写if()then命令_Batch File_If Statement - Fatal编程技术网

Batch file 我需要帮助编写if()then命令

Batch file 我需要帮助编写if()then命令,batch-file,if-statement,Batch File,If Statement,我正在尝试编写一个文件,它将终止所有运行的任务。我知道如何终止这些任务,但我需要帮助编写if()then命令。我所要做的就是到达的位置。如果命令提示符关闭,则计算机将注销。另外,我知道如何执行注销命令shutdown/l。有人能帮我吗?在后台运行此命令: @echo off :loopme start /WAIT "c:\path\to\batch.file.bat" goto loopme 把它放在“开始”菜单的“启动”文件夹中。。。而且。。。瞧 希望这有帮助~CSS可能有一个监视器批处理文

我正在尝试编写一个文件,它将终止所有运行的任务。我知道如何终止这些任务,但我需要帮助编写if()then命令。我所要做的就是到达的位置。如果命令提示符关闭,则计算机将注销。另外,我知道如何执行注销命令shutdown/l。有人能帮我吗?

在后台运行此命令:

@echo off
:loopme
start /WAIT "c:\path\to\batch.file.bat"
goto loopme
把它放在“开始”菜单的“启动”文件夹中。。。而且。。。瞧


希望这有帮助~CSS可能有一个监视器批处理文件,用于检查主批处理文件的PID是否存在…
主文件:

@echo off
setlocal
title Main Batch File
set T=%TEMP%\sthUnique.tmp
wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%T%
set /P A=<%T%
set PID=%A:~16%
echo %PID% > pid.pref
rem The rest of the file is down here...
监视器批处理文件检查是否存在具有相同PID的进程,如果不存在,则关闭计算机。现在,如果一个进程在主批处理文件关闭后立即打开,并且Windows为新进程提供了相同的PID,那么您可能会不走运,但这是极不可能的。
顺便说一下,首先启动监视器,它将自己启动主文件


注意:我没有测试过这一点。

或者如果没有办法,可以在不被点击触发的情况下重新启动批处理文件。或使批处理文件无法关闭的方法。
@echo off
setlocal
title Monitor
start mainfile.bat
ping localhost -n 1 -w 2000 >NUL
< pid.pref (set /p pid=)
:loop
tasklist /fi "PID eq %pid%" |find ":" > nul
if "%ERRORLEVEL%"=="1" (
    shutdown.exe /s /t 00
    exit
)
goto loop