简体   繁体   English

在Windows Server 2012上从计划任务运行批处理文件不会写入光盘

[英]Running batch file from scheduled task on windows server 2012 won't write to disc

I wrote a short batch file for restarting two services every night and write some lines to a txt-file in the same folder. 我写了一个简短的批处理文件,每晚每晚都要重新启动两个服务,然后在同一文件夹中的txt文件中写一些行。 According to the history of the scheduled task the task ran succesfully, but the txt-file is not created. 根据计划任务的历史记录,任务成功运行,但未创建txt文件。

At first I thought this was beacause of permissions, but when I escalated the permissions of the user running the task to max on both the batch file and the folder, the result stayed the same. 起初我以为这是因为权限,但是当我将运行任务的用户的权限升级到批处理文件和文件夹上的max时,结果保持不变。

If I run the batch-file manually it does what it's supposed to do. 如果我手动运行批处理文件,它将执行应做的工作。

What am I missing here? 我在这里想念什么?

Source: 资源:

@echo off
set now=%date:~6,4%%date:~3,2%%date:~0,2%

@echo. >>servicerestartlog.txt
@echo.%now% >>servicerestartlog.txt
net stop "IntegratorService"
IF ERRORLEVEL 0 @echo STOP INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo STOP INTEGRATOR FAILED>>servicerestartlog.txt
net stop "SchedulerService"
IF ERRORLEVEL 0 @echo STOP SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo STOP SCHEDULER FAILED>>servicerestartlog.txt

net start "IntegratorService"
IF ERRORLEVEL 0 @echo START INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo START INTEGRATOR FAILED>>servicerestartlog.txt

net start "SchedulerService"
IF ERRORLEVEL 0 @echo START SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo START SCHEDULER FAILED>>servicerestartlog.txt

exit

Solution that worked for me: 对我有用的解决方案:

In addition to the path to the script I wanted to run I had to add the folder the script was supposed to start in. This can be set in the Start in (optional) - textbox under edit action. 除了要运行的脚本的路径之外,我还必须添加脚本应该在其中开始的文件夹。可以在“编辑”下的“开始于(可选)-文本框”中进行设置。 Seems it's not so optional after all... 似乎毕竟不是那么可选...

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

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