.BATファイルがあり、Windowsのタスクスケジューラを使用して自動的に実行しようとしている場合は(Windows)、(Task Scheduler)手動でタスクを実行しないと実行されないという問題が発生した可能性があります。
コンピューターが起動するたびに一時フォルダー内のすべてを削除するバッチファイルを作成しました。私はタスクスケジューラ(Task Scheduler)で基本的なタスクを作成し、最高のものを望んでいました。残念ながら、コンピュータが起動しても何も起こりませんでした。試行錯誤の末、スクリプトを実行する方法を見つけました。
この記事では、手動で介入せずにバッチファイルを実行するために調整する必要のある設定と権限について説明します。
ステップ1:File/Folderのアクセス許可を確認する
この問題を修正するための最初の手順は、タスクスケジューラ(Task Scheduler)でスクリプトを実行するために使用しているアカウントに、スクリプトを含むフォルダー、スクリプト自体、およびスクリプトの実行時にスクリプトがアクセスするフォルダー/ファイルに対するフルコントロールのアクセス許可があることを確認することです。(Full Control)
たとえば、次のバッチスクリプトを以下に作成しました。
set folder="C:\test"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
.BATファイルをDocumentsフォルダーに保存しました。パスはC:\Users\username\Documentsです。C:\ Users \ usernameに移動し、 Documents(Documents)フォルダーを右クリックして、 [プロパティ(Properties)]をクリックしました。次に、[セキュリティ(Security)]タブをクリックしました。

ご覧のとおり、ユーザーアカウントAseemが明示的に追加され、フルコントロール(Full Control)のアクセス許可が付与されています。ここで、スクリプトを含むフォルダーとスクリプト自体に対して同じことを行う必要があります。スクリプトを含むフォルダーにアクセス許可を付与した場合、そうではないので、行ってもよいと思い込まないでください。最後に、スクリプトが操作するすべてのファイルとフォルダーにアクセス許可を設定します。
私の場合、C:\testに移動し、そのフォルダーを右クリックして、フルコントロール(Full Control)のアクセス許可を持つユーザーアカウントをそこに追加する必要がありました。これを行わなければならないのはちょっと面倒ですが、スクリプトを実行する唯一の方法です。
注:スクリプトの実行に使用されているアカウントは、コンピューターのローカルAdministratorsグループの一部である必要があります。私の場合、Aseemアカウントは管理者アカウントであるため、ローカルのAdministratorsグループの一部です。 (Note: The account that is being used to run the script has to be part of the local Administrators group on the computer. In my case, the Aseem account is an administrator account and therefore part of the local Administrators group. )
手順2:タスクスケジューラの設定を確認する(Task Scheduler Settings)
次に、タスクスケジューラ(Task Scheduler)に移動し、そこで適切な設定を変更します。タスクスケジューラ(Task Scheduler)を開き、[アクティブなタスク]( Active Tasks)セクションでタスクを見つけます。それらはアルファベット順にリストされるべきです。

それをダブルクリックすると、同じウィンドウでタスクが単独で開きます。タスクを編集するには、タスクを右クリックして[プロパティ(Properties)]を選択する必要があります。

ここにはいくつかのタブがあり、いくつかチェックして変更する必要があります。まず、 [全般(General)]タブで、タスクの実行に使用されているユーザーアカウントを確認する必要があります。私の場合、これはAseemアカウントです。これは、ファイルシステムで以前にアクセス許可を与えたもので、コンピューターのAd (Aseem)ministrators(Administrators)グループの一部です。

次に、 [ユーザーがログオンしているかどうかに関係なく実行する( Run whether user is logged on or not)]オプションを選択し、[構成]ボックスで(Configure for)[Windows Vista、WindowsServer2008 ]を選択する必要があります。

[アクション(Actions)]タブで、スクリプトを選択し、[編集]をクリックして、[(Edit)開始](オプション)(e Start in (optional))ボックスにスクリプトを含むフォルダーへのパスを追加する必要があります。これは不要に思えるかもしれませんが、そうではありません。私の場合、ボックスにC:\Users\Aseem\Documents\を入力しました。
次に、[ OK(OK) ]をクリックして設定を保存します。これを行うと、タスクを実行するユーザーアカウントのパスワードを入力する必要があるダイアログが表示される場合があります。これにより、別の要件が発生します。パスワードのないアカウントは使用できません。タスクを実行するには、ユーザーアカウントにパスワードが必要です。

最後に、タスクスケジューラ(Task Scheduler)でタスクを手動で一度実行して、タスクが実行されることを確認する必要があります。すべての設定を変更した後で手動で正常に実行される場合は、トリガーされるはずのときに実行されるはずです。私の場合、それは起動時に発生するはずでしたが、変更を加えた後、すべてが正常に機能しました。

スクリプトの実行時にドメイン内のさまざまなコンピューターにアクセスしている場合は、ドメイン管理者アカウントを使用してタスクを実行する必要があることに注意してください。これにより、アカウントにリモートコンピューターにアクセスするための十分なアクセス許可が付与されます。
注意すべきもう1つの項目は、スクリプトがネットワーク共有上のリソースにアクセスするかどうかです。スクリプトが文字を使用してネットワークにアクセスしている場合、スクリプトが実行されない可能性があります。たとえば、F:\data\\\machinename\share_name\data\ Âを使用する必要があります。それでもスクリプトを実行できない場合は、ここにコメントを投稿してください。サポートさせていただきます。楽しみ!
Fix Scheduled Task Won’t Run for .BAT File
If you have a .BΑT fіle and you’re trying to get it to run automatically using Taѕk Scheduler in Windows, you might have run into the issue where it simply doesn’t run unless you manually run the task.
I created a batch file that deletes everything inside a temp folder whenever the computer starts up. I created a basic task in Task Scheduler and hoped for the best. Unfortunately, nothing happened when my computer booted up. After a lot of trial and error, I figured out how to get the script to run.
In this article, I’m going to walk you through the settings and permissions you need to adjust in order to get your batch file to run without manual intervention.
Step 1: Check File/Folder Permissions
The first step to fixing this issue is ensuring that the account you are using to run the script in Task Scheduler has Full Control permissions on the folder containing the script, the script itself, and any folders/files that the script touches when it runs.
For example, I created the following batch script below:
set folder="C:\test"
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 Documents folder. The path is C:\Users\username\Documents. I went to C:\Users\username, right-clicked on the Documents folder, and clicked on Properties. Then I clicked on the Security tab.

As you can see, the user account Aseem has been explicitly added and given the Full Control permission. Now you have to do the same thing for the folder that contains the script and for the script itself. Don’t just assume that if you give permissions to the folder containing the script, you’re good to go, because you’re not. Lastly, set permissions on any files and folders that the script will interact with.
In my case, I had to go to C:\test, right-click on that folder and add my user account there with Full Control permissions. It’s kind of annoying that you have to do this, but it’s the only way to get the script to run.
Note: The account that is being used to run the script has to be part of the local Administrators group on the computer. In my case, the Aseem account is an administrator account and therefore part of the local Administrators group.
Step 2: Check Task Scheduler Settings
Now let’s go to Task Scheduler and change the appropriate settings there. Open Task Scheduler and find your task under the Active Tasks section. They should be listed out in alphabetical order.

Double-click on it and it’ll open the task by itself in the same window. In order to edit the task, you’ll have to right-click on it and choose Properties.

There are several tabs and a couple of things have to checked and changed here. Firstly, on the General tab, you need to check the user account that is being used to run the task. In my case, it’s the Aseem account, which I had given permissions to earlier on the file system and which is part of the Administrators group on the computer.

Next, you have to choose the Run whether user is logged on or not option and choose Windows Vista, Windows Server 2008 in the Configure for box.

On the Actions tab, you have to select the script, click on Edit and then add in the path to the folder containing the script in the Start in (optional) box. This may seem unnecessary, but it’s not. In my case, I put in C:\Users\Aseem\Documents\ in the box.
Now click on OK to save the settings. When you do this, a dialog may appear where you have to enter the password for the user account that will run the task. This brings up another requirement. You can’t use an account that doesn’t have a password. The user account has to have a password in order for the task to run.

Lastly, you should run the task manually once in Task Scheduler to make sure it runs. If it runs fine manually after you changed all the settings, then it should run when it’s supposed to be triggered. In my case, it was supposed to happen on startup and after I made the changes, everything worked fine.

Note that if your script is accessing different computers in a domain when run, you should try to use the domain administrator account to run the task. This will ensure the account has enough permissions to access the remote computers.
Another item to note is if your script accesses resources on a network share. If your script is using letters to access the network, it may not run. For example, instead of using F:\data\, you should use \\machinename\share_name\data\ in the script. If you still can’t get your script to run, post a comment here and I’ll try to help. Enjoy!