2016-06-06 1 views
0

몇 가지 명령을 호출하고 궁극적으로 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 
+3

배치 파일을 사용하는 이유는 무엇입니까? 전체 스크립트에 PowerShell을 사용하기 만하면됩니다. –

+0

이 스크립트를 실행할 때마다 PowerShell 스크립트를 덮어 씁니다. PowerShell 스크립트를 사용하는 이유는 전자 메일 명령을 별도의 파일에 보관하여 필요할 경우 변경할 수 있기 때문입니다. 그래서 저는 그 부분을 자체 파일에 보관하고 싶습니다. –

+0

배치 파일이 필요하지 않은 대체 접근 방식을 권장합니다. –

답변

0

그것은 실행하는 사용자 계정으로 할 수있는 가능성이 뭔가가있다. 작업 스케줄러에서이를 구성 할 수 있다면 자신의 계정이나 "대화 형 사용자"로 bat 파일을 실행 시키십시오. 그렇다면 그것은 작동합니다.

이메일은 어떻게 전송됩니까? 아마도 Outlook을 사용하고 있습니까? 자동화 된 Outlook에는 몇 가지 보안 제약이 있습니다. 사용자 A가 열면 사용자 B의 자동화가 허용되지 않습니다.

+0

이메일은 Outlook에서 전송됩니다. 내가 파일과 작업을 만들 때 나는 같은 사용자 계정을 사용하고 있지만. 작업 스케줄러에서 가장 높은 권한으로 작업을 실행하도록 설정하고 동일한 사용자로 실행합니다. –

+0

상승 된 권한은 Outlook에서 다른 사용자로 계속 표시됩니다. 스크립트를 실행하기 전에 Outlook을 종료하면 문제가되지 않습니다. 대신 sheduler에서 PowerShell ISE를 실행 한 다음 스크립트를 디버그하여 오류가 발생한 위치를 확인하십시오. –

-1

다음 명령을 사용하여 powershell 스크립트를 실행하십시오. C : \ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe -NoProfile -ExecutionPolicy Bypass- 파일 "& %"% PowerShellScriptPath % ""

관련 문제