Batch file called by scheduled task throws error when scheduled, runs fine when double clicked

徘徊边缘 提交于 2019-12-06 10:53:12

问题


I have a batch file that maps a networked drive. About a week or so ago the password expired, so the program calling the batch file started throwing errors.

I've updated the password in the batch file, and when I double click on the batch file, the drive maps fine. However, when the scheduled task kicks off, I get the following error:

Logon failure: unknown user name or bad password.

Anyone seen this before? I've tried recreating the scheduled task, but it doesn't seem to make any difference.

EDIT

I've updated the properties of the scheduled task, which isn't the problem. The problem seems to be the username and password in the batch file. The strange thing is if I log on interactively and double click the executable, everything works perfectly.

The last time the job ran it threw a "semaphore timeout period has expired" error. I've never seen this particular error before, but it seems like it was actually logged on and trying to copy files when this happened.

EDIT

I've revised my code to make it as simple as possible. I'm using a batch file to map the drive, then using code to transfer the files. I still run into the same issue - it works fine when I double click the batch file, but once I throw Scheduler into the picture, it throws a "Bad username or invalid password" error.

Occasionally when I'm trying to run the file by double clicking on it, I get a "Could not find part of the path" error. This says to me the drive mapping actually worked but something failed when it was trying to copy. (Most of the time, testing by double clicking works fine)


回答1:


The username and password associated with the task when you created it is no longer valid or has changed. This occurs generally when creating the task and forgetting to select the option not to store the password. When your password is set to expire, then you will meet this problem everytime you will have to reset your password. Make sure to do as on the image :




回答2:


It sounds like the username and/or password associated with the scheduled task is no longer correct. The batch file is likely OK, you just need to change the properties of the scheduled task.




回答3:


I ran into something similar while testing a new powershell script we wrote to create a scheduled task to back up to one or more network locations. I had to go through a number of iterations, and when I decreased from two network locations to one, the scheduled task stopped working, with individual steps in the called script giving "Logon failure: unknown user name or bad password" errors, though when I copied the arguments and ran them from the command line they worked.

After reading this question and Tim's comment, I tried deleting the scheduled task and re-creating it. After that it worked. I would concur that the scheduled task likely cached something.




回答4:


From: https://danblee.com/log-on-as-batch-job-rights-for-task-scheduler/

Go to the Start menu. Run. Type secpol.msc and press Enter. The Local Security Policy manager opens. Go to Security Settings – Local Policies – User Rights Assignment node. Double click Log on as a batch job on the right side. Click Add User or Group… Select the user and click OK.



来源:https://stackoverflow.com/questions/12301798/batch-file-called-by-scheduled-task-throws-error-when-scheduled-runs-fine-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!