2

I made a bat file which restarts 2 services, and I have it run in task scheduler. If I run the bat file normally, I can see it logging in current directory as the bat file. But if I run it through task scheduler, I can see the bat runs, like in services window, I can see the services restarting, but it doesn't log anything.... Does anyone know what the issue is?

This is on windows server 2008 r2 64-bit.

Thanks

@echo off
SET waittimeseconds_sp_fix=15
SET logfilename_sp_fix="SPSearchFix.log"

echo %date% %time% - Restart starting >> %logfilename_sp_fix%


net stop SPTimerV4 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Stopped timer service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Stopped timer service >> %logfilename_sp_fix%
    exit
)

timeout %waittimeseconds_sp_fix%

net stop osearch14 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Stopped search service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Stopped search service >> %logfilename_sp_fix%
    exit
)    

timeout %waittimeseconds_sp_fix%

net start SPTimerV4 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Started timer service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Started timer service >> %logfilename_sp_fix%
    exit
)

timeout %waittimeseconds_sp_fix%

net start osearch14 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Started search service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Started search service >> %logfilename_sp_fix%
    exit
)

timeout %waittimeseconds_sp_fix%

echo %date% %time% - Restart completed >> %logfilename_sp_fix%

echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
  • Try specifying an absolute path in your SET logfilename_sp_fix="SPSearchFix.log" line. E.g.: SET logfilename_sp_fix="c:\temp\SPSearchFix.log", and ensure all users have write access to that folder. – Ƭᴇcʜιᴇ007 Jan 26 '16 at 17:09
  • I figured it out, it was logging to system32 folder for some reason, but putting absolute path worked. – omega Jan 26 '16 at 17:11
  • That's what I figured, I'll post up an actual answer. ;) – Ƭᴇcʜιᴇ007 Jan 26 '16 at 17:11
2

When you run things in the Task Scheduler, the working folder (by default) is %windri%\system32. So any files created by the task, that don't have a path specified, will be written there (or at least it will attempt to write them there).

To avoid this, specify an absolute path in your SET logfilename_sp_fix="SPSearchFix.log" line.

E.g.: SET logfilename_sp_fix="c:\temp\SPSearchFix.log

And ensure all users (or at least the user the task runs as) have write access to that chosen folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.