I have a batch file that calls a few commands and ultimately runs a powershell script. It runs fine manually, however in task scheduler, I can see that it completes some of the actions but doesn't actually run the powershell script (last command in the bat file) The script is created/overwritten by a java file where it sends out emails. Everything updates and necessary but ultimately the emails are never sent. When I click on the bat file in Win explorer, it works as expected.
我有一个调用一些命令的批处理文件,最终运行一个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 个解决方案
#1
0
It has likely something to do with the executing user account. If you can configure that in your task scheduler, have your bat file executed under your own account or "the interactive user". Then it should work.
它可能与执行用户帐户有关。如果您可以在任务计划程序中配置它,请在您自己的帐户或“交互式用户”下执行您的bat文件。然后它应该工作。
How are the emails sent? Using Outlook perhaps? Outlook has some security constraints when automated. If it is opened by user A it will not allow automation by user B.
电子邮件是如何发送的?也许使用Outlook? Outlook自动化时有一些安全限制。如果用户A打开它,则不允许用户B自动化。
#2
-1
Please try below command to run powershell script. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -file "& '%PowerShellScriptPath%'"
请尝试以下命令运行powershell脚本。 C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe -NoProfile -ExecutionPolicy Bypass -file“&'%PowerShellScriptPath%'”
#1
0
It has likely something to do with the executing user account. If you can configure that in your task scheduler, have your bat file executed under your own account or "the interactive user". Then it should work.
它可能与执行用户帐户有关。如果您可以在任务计划程序中配置它,请在您自己的帐户或“交互式用户”下执行您的bat文件。然后它应该工作。
How are the emails sent? Using Outlook perhaps? Outlook has some security constraints when automated. If it is opened by user A it will not allow automation by user B.
电子邮件是如何发送的?也许使用Outlook? Outlook自动化时有一些安全限制。如果用户A打开它,则不允许用户B自动化。
#2
-1
Please try below command to run powershell script. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -file "& '%PowerShellScriptPath%'"
请尝试以下命令运行powershell脚本。 C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe -NoProfile -ExecutionPolicy Bypass -file“&'%PowerShellScriptPath%'”