Bat文件手动运行,不完成任务调度程序

时间:2016-06-06 17:08:33

标签: powershell batch-file taskscheduler

我有一个调用一些命令的批处理文件,最终运行一个PowerShell脚本。它可以手动运行,但是在任务调度程序中,我可以看到它完成了一些操作,但实际上并没有运行powershell脚本(bat文件中的最后一个命令)脚本由它发送的java文件创建/覆盖发电子邮件。一切都更新和必要,但最终电子邮件永远不会发送。当我在Win explorer中单击bat文件时,它按预期工作。

@echo off
set Pathname="C:\Users\administrator\Documents\EmailNotification\EmailNotificationJava"
cd %Pathname%
REM ECHO Directory: C:\Users\administrator\Documents\Notification
CALL IndividualCMDCommands.bat
set Pathname="C:\Users\administrator\Documents\EmailNotification\EmailNotificationJava\src"
cd %Pathname%
XCOPY C:\Users\administrator\Documents\EmailNotification\EmailNotificationJava\*.txt C:\Users\administrator\Documents\EmailNotification\EmailNotificationJava\src /Y
javac -cp .;C:\Users\administrator\Documents\EmailNotification\EmailNotificationJava\joda-time-2.9.3\joda-time-2.9.3.jar ParseInfo.java
java -cp .;C:\Users\administrator\Documents\EmailNotification\EmailNotificationJava\joda-time-2.9.3\joda-time-2.9.3.jar ParseInfo 
ECHO ParseInfo
REM set Pathname="C:\Users\administrator\Documents\Notification"
REM cd %Pathname%
ECHO Powershell
REM SET ThisScriptsDirectory="C:\Users\administrator\Documents\EmailNotification\EmailNotificationJava\src"
SET PowerShellScriptPath=%TC:\Users\administrator\Documents\EmailNotification\EmailNotificationJava\PSCMD.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%'";
ECHO Complete

2 个答案:

答案 0 :(得分:0)

它可能与执行用户帐户有关。如果您可以在任务计划程序中配置它,请在您自己的帐户或“交互式用户”下执行您的bat文件。然后它应该工作。

电子邮件是如何发送的?也许使用Outlook? Outlook自动化时存在一些安全限制。如果用户A打开它,则不允许用户B自动执行。

答案 1 :(得分:-1)

请尝试使用以下命令运行powershell脚本。 C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe -NoProfile -ExecutionPolicy Bypass -file“&'%PowerShellScriptPath%'”

相关问题