我制作了一个用于重新启动 2 个服务的 bat 文件,并将其在任务计划程序中运行。如果我正常运行该 bat 文件,我可以看到它以 bat 文件的形式记录在当前目录中。但如果我通过任务计划程序运行它,我可以看到 bat 运行,就像在服务窗口中一样,我可以看到服务重新启动,但它没有记录任何内容......有人知道问题是什么吗?
这是在 Windows Server 2008 R2 64 位上。
谢谢
@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%
答案1
当您在任务计划程序中运行程序时,工作文件夹(默认)是%windri%\system32
。因此,任务创建的任何未指定路径的文件都将写入那里(或至少它将尝试将它们写入那里)。
为了避免这种情况,请在您的行中指定绝对路径SET logfilename_sp_fix="SPSearchFix.log"
。
例如:SET logfilename_sp_fix="c:\temp\SPSearchFix.log
并确保所有用户(或至少是运行任务的用户)对所选文件夹具有写访问权限。