我有一个批处理文件,它调用一些命令并最终运行powershell脚本。它手动运行得很好,但是在任务调度器中,我可以看到它完成了一些操作,但实际上并没有运行powershell脚本( bat文件中的最后一个命令)脚本是由它发送电子邮件的java文件创建/覆盖的。每件事都会更新,也是必要的,但最终电子邮件永远不会发送。当我点击Win资源管理器中的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发布于 2016-06-07 05:11:07
这可能与正在执行的用户帐户有关。如果你可以在你的任务调度器中配置它,让你的bat文件在你自己的账户或者“交互式用户”下执行。那么它应该是有效的。
电子邮件是如何发送的?也许是在使用Outlook?Outlook在自动化时有一些安全限制。如果它是由用户A打开的,它将不允许用户B自动操作。
发布于 2016-06-08 01:26:34
请尝试下面的命令来运行powershell脚本。C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy绕过-file "& '%PowerShellScriptPath%'“
https://stackoverflow.com/questions/37663159
复制相似问题