JasonRobi
JasonRobi

Reputation: 31

BAT file will NOT run in Windows 10 Task Scheduler but WILL run as Admin or in elevated comand prompt

My BAT file (below) runs perfectly when I run it from an elevated command prompt or Right-Click -> Run as Administrator. However, when I put it in my Windows 10 Task Scheduler, it will not run.

What I've tried: -- Security Options of the task: I've tried both SYSTEM and a domain admin account. -- I select "Run with Highest Privileges." -- I have Selected "Windows 10" in the "Configure For:" dropdown. -- In the EDIT ACTION window, I have specified the location (c:\script) of the BAT file in "Start in (optional)" section -- In "Program/Script” I have tried "C:\scripts\script.bat" (without the quotes). I have tried listing just “script.bat" (without the quotes). And, I have also tried ".\script.bat" (without the quotes). -- I have created the extra lines in the BAT file to copy the file from the System32 directory to another (less secure) location before trying to copy it to the network drive. (I feel like this is unnecessary, and it didn't seem to help with the overall problem.)

*******************BEGIN BAT FILE******************

@Echo off

REM (maps network drive)
NET use Z: \\SERVER\PATH

REM (copies any archived security event viewer logs to the network) 
IF EXIST "%SystemRoot%\System32\Winevt\Logs\Archive-Securit*.evtx" (     
      xcopy "%SystemRoot%\System32\Winevt\Logs\Archive-Securit*.evtx" c:\test\ /Y      
      xcopy "c:\test\Archive-Securit*.evtx" \\SERVER\PATH\%computername% /Y

REM (deletes files on the local machine after the files are verified to be on the network share)      
     FORFILES /p "Z:\PATH\%computername%" /c "cmd /c del %SystemRoot%\System32\Winevt\Logs\@file"      
     FORFILES /p "Z:\PATH\%computername%" /c "cmd /c del c:\test\@file"

) ELSE ( 
REM Do nothing 
)

******************END BAT FILE***************

Upvotes: 1

Views: 1169

Answers (1)

JasonRobi
JasonRobi

Reputation: 31

I figured out my problem. Group Policy had Domain Admins in the Computer Configuration -> Windows Settings -> Security Settings -> Local Policies -> User Rights Assignment -> "Deny logon as a batch job."

After removing Domain Admins from this listing and running gpupdate on the machine, I was able to successfully run the BAT in the Task Scheduler (Assuming I had the domain admin user listed in the Security Options of the task).

Upvotes: 2

Related Questions