我正在尝试创建一个小型批处理文件,它将启动程序并更改计算机的时间,并在程序关闭时更改时间。
我的程序并没有真正起作用,所以我在寻求你的帮助。这是我到目前为止所得到的:
:Item_1
tzutil /s "Hawaiian Standard Time"
:Item_2
tzutil /s "W. Europe Standard Time"
@echo off
Start "" "C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe"
set Programma="C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe"
tasklist |find /i "%Programma%"nul
if %errorlevel% == 0 (
'%t%' == '%t%' GOTO Item_%1%
) else (
'%t%' == '%t%' GOTO Item_%2%
)
答案 0 :(得分:0)
goto
就是这样说的。它转到标签。而已。在那里,cmd
继续"像往常一样" - 逐行。所以它tzutil /s "Hawaiian Standard Time"
,紧接着是tzutil /s "W. Europe Standard Time"
表达式'%t%' == '%t%'
似乎完全是胡说八道。
遵循脚本的逻辑,它可以简化为:
@echo off
set "Programma=C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe"
Start "" "%Programma%"
tasklist |find /i "%Programma%">nul
if %errorlevel% == 0 (
tzutil /s "Hawaiian Standard Time"
) else (
tzutil /s "W. Europe Standard Time"
)
(你忘了重定向>
)
答案 1 :(得分:0)
@echo off
setlocal enableextensions
rem before launching minecraft change the TZ to EU.
tzutil /s "W. Europe Standard Time"
set "Programma=C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe"
Start "" "%Programma%"
rem give a break of 3mins before starting the loop
@timeout /T 180 /nobreak >nul
:isrunning
tasklist /FI "IMAGENAME eq MinecraftLauncher.exe" /FI "STATUS eq running" /NH /FO csv | findstr /ic:"MinecraftLauncher.exe" >nul
if errorlevel 0 (
rem :: Software found, then wait 3 mins before another loop
@timeout /T 180 /nobreak >nul
goto isrunning
) else (
rem :: Software not found, we can now change the TZ before exit.
tzutil /s "Hawaiian Standard Time"
exit /b 0
)