首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bat文件手动运行,未与任务计划程序一起完成

Bat文件手动运行,未与任务计划程序一起完成
EN

Stack Overflow用户
提问于 2016-06-07 01:08:33
回答 2查看 538关注 0票数 0

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

代码语言:javascript
复制
@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
EN

回答 2

Stack Overflow用户

发布于 2016-06-07 05:11:07

这可能与正在执行的用户帐户有关。如果你可以在你的任务调度器中配置它,让你的bat文件在你自己的账户或者“交互式用户”下执行。那么它应该是有效的。

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

票数 0
EN

Stack Overflow用户

发布于 2016-06-08 01:26:34

请尝试下面的命令来运行powershell脚本。C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy绕过-file "& '%PowerShellScriptPath%'“

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37663159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档