简体   繁体   English

Windows 任务计划程序中的 wscript.exe

[英]wscript.exe in Windows Task Scheduler

I've written a batch file that checks if Hamachi Service is working and if it is not it starts it.我写了一个批处理文件来检查 Hamachi 服务是否正在工作,如果不是,它会启动它。 I made this script working in background by writing vbs script我通过编写 vbs 脚本使这个脚本在后台工作

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

and executing it并执行它

wscript.exe "invisible.vbs" "HamachiRestart.bat"

HamachiRestart.bat looks like this: HamachiRestart.bat 看起来像这样:

        for /F "tokens=3 delims=: " %%H in ('sc query "Hamachi2Svc" ^| findstr "        STATE"') do (
      if /I "%%H" NEQ "RUNNING" (
        net start "Hamachi2Svc"
        echo %COMPUTERNAME% %DATE% %TIME% :: Uruchomiono usługę >> LOG.txt
      )
    )
    echo %COMPUTERNAME% %DATE% %TIME% :: OK >> LOG.txt
exit

and when I'm executing it from console it is working fine (restart service and add line to log) but main problem is that when I try to schedule it in Windows Task Scheduler it is working partially (restart service but log is empty...)当我从控制台执行它时它工作正常(重新启动服务并将行添加到日志)但主要问题是当我尝试在 Windows 任务计划程序中安排它时它部分工作(重新启动服务但日志为空.. .)

Any ideas how to fix it?任何想法如何解决它? I just need this log file working.我只需要这个日志文件工作。

I think the problem is the relative path of the log file, you need the absolute path like: C:\\temp\\LOG.txt .我认为问题是日志文件的相对路径,您需要绝对路径,如: C:\\temp\\LOG.txt

If you start from console the log file can be created in the same directory, but if you try to schedule it the log file can't be created because the current directory is a system dir.如果从控制台启动,可以在同一目录中创建日志文件,但是如果您尝试对其进行调度,则无法创建日志文件,因为当前目录是系统目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM