wscript.exe in Windows Task Scheduler

952 Views Asked by At

I've written a batch file that checks if Hamachi Service is working and if it is not it starts it. I made this script working in background by writing vbs script

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

and executing it

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

HamachiRestart.bat looks like this:

        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...)

Any ideas how to fix it? I just need this log file working.

1

There are 1 best solutions below

1
On

I think the problem is the relative path of the log file, you need the absolute path like: 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.