When you’ve got a .BAT file and also you’re making an attempt to get it to run robotically utilizing Job Scheduler in Home windows, you may need run into the difficulty the place it merely doesn’t run except you manually run the duty.
I created a batch file that deletes all the pieces inside a temp folder at any time when the pc begins up. I created a primary job in Job Scheduler and hoped for one of the best. Sadly, nothing occurred when my laptop booted up. After lots of trial and error, I found out get the script to run.
On this article, I’m going to stroll you thru the settings and permissions it is advisable modify as a way to get your batch file to run with out handbook intervention.
Step 1: Test File/Folder Permissions
Step one to fixing this concern is making certain that the account you might be utilizing to run the script in Job Scheduler has Full Management permissions on the folder containing the script, the script itself, and any folders/information that the script touches when it runs.
For instance, I created the next batch script beneath:
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
I saved the .BAT file to my Paperwork folder. The trail is C:UsersusernameDocuments. I went to C:Usersusername, right-clicked on the Paperwork folder, and clicked on Properties. Then I clicked on the Safety tab.
As you may see, the consumer account Aseem has been explicitly added and given the Full Management permission. Now you need to do the identical factor for the folder that comprises the script and for the script itself. Don’t simply assume that should you give permissions to the folder containing the script, you’re good to go, since you’re not. Lastly, set permissions on any information and folders that the script will work together with.
In my case, I needed to go to C:check, right-click on that folder and add my consumer account there with Full Management permissions. It’s sort of annoying that you need to do that, nevertheless it’s the one strategy to get the script to run.
Observe: The account that’s getting used to run the script must be a part of the native Directors group on the pc. In my case, the Aseem account is an administrator account and due to this fact a part of the native Directors group.
Step 2: Test Job Scheduler Settings
Now let’s go to Job Scheduler and alter the suitable settings there. Open Job Scheduler and discover your job underneath the Energetic Duties part. They need to be listed out in alphabetical order.
Double-click on it and it’ll open the duty by itself in the identical window. With the intention to edit the duty, you’ll need to right-click on it and select Properties.
There are a number of tabs and a few issues need to checked and adjusted right here. Firstly, on the Basic tab, it is advisable examine the consumer account that’s getting used to run the duty. In my case, it’s the Aseem account, which I had given permissions to earlier on the file system and which is a part of the Directors group on the pc.
Subsequent, you need to select the Run whether or not consumer is logged on or not possibility and select Home windows Vista, Home windows Server 2008 within the Configure for field.
On the Actions tab, you need to choose the script, click on on Edit after which add within the path to the folder containing the script in the Begin in (optionally available) field. This may increasingly appear pointless, nevertheless it’s not. In my case, I put in C:UsersAseemDocuments within the field.
Now click on on OK to avoid wasting the settings. While you do that, a dialog could seem the place you need to enter the password for the consumer account that may run the duty. This brings up one other requirement. You possibly can’t use an account that doesn’t have a password. The consumer account has to have a password to ensure that the duty to run.
Lastly, it is best to run the duty manually as soon as in Job Scheduler to ensure it runs. If it runs high-quality manually after you modified all of the settings, then it ought to run when it’s imagined to be triggered. In my case, it was imagined to occur on startup and after I made the modifications, all the pieces labored high-quality.
Observe that in case your script is accessing completely different computer systems in a site when run, it is best to attempt to use the area administrator account to run the duty. This may make sure the account has sufficient permissions to entry the distant computer systems.
One other merchandise to notice is that if your script accesses sources on a community share. In case your script is utilizing letters to entry the community, it might not run. For instance, as a substitute of utilizing F:information, it is best to use machinenameshare_namedata within the script. In the event you nonetheless can’t get your script to run, put up a remark right here and I’ll attempt to assist. Get pleasure from!