Task scheduler scheduled task with priority changed to normal fails on disk IO

2021-12-07T11:17:03.29+00:00

Hi
I test with Windows 10 Ver 1803.
I have scheduled a task which runs a .NET application which write something to disk. I need to run this application with normal priority, so I did some tricky way and change the task priority from default below normal to normal (https://aavtech.site/2018/01/windows-task-scheduler-changing-task-priority/). From then by, this task fails with an IOException, which I see in Event viewer.
Interestingly other triggering options like manually or scheduled on an specific time, runs it normally.
I understand that Windows will restrict Disk IO for a changed priority Task while it`s trigger is on Startup. Are there any security policies or other settings that would interfere with scheduled task, on this circumstance?

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,090 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 31,571 Reputation points
    2021-12-19T14:55:24.107+00:00

    As you see in this log, the programs starts without first disk testing:

    That means that it sees the drive letter but not the temp folder itself. I have removed the tests for the volume, Try this.

       # Update 19-Dec - Check for the folder and driveletter, not the volume.  
       Start-Transcript -Path ("C:\temp\{0}-{1}-PSConsole.txt" -f $env:USERNAME, (get-date -format "yyyyMMdd-HHmmss" ))            # This is your log file 
       $Folder = $env:TEMP              # This is the target folder that we need to access.  Did you use this one? 
       ###$Folder = "B:\temp1"          # This is the target folder that we need to access. 
       "Temp folder is {0}" -f $Folder  
       $Wait = $true
       $count = 0 
       $limit = 10                   # how many times should we retry (10 minutes) 
       $launch = $false
       $DriveLetter = $Folder.Split(":")[0]
       "{0} - I am going wait on the {1} drive." -f (get-date),   $DriveLetter
       "{0} - Here are the volumes that I see." -f (get-date)
       Get-Volume | Format-Table
       Try { 
           Get-Item "$($DriveLetter):\" -ErrorAction Stop
           "{0} - I see the {1} drive!" -f (get-date), $DriveLetter 
       } catch {
           "{0} - I don't see a {1} drive." -f (get-date), $DriveLetter 
       } 
    
       ""
       "{0} - Main loop." -f (get-date)
       while ($wait) {
           $Drive = Get-Item "$($DriveLetter):\" -ErrorAction SilentlyContinue
           if ($Drive) {        # do we see the drive letter 
               "{0} - I see the drive." -f (get-date) 
               New-Item -Path $Folder -ItemType Directory -ErrorAction SilentlyContinue         # Try to create the temp folder @ 19-Dec update   
               if (Test-Path $Folder) {
                   "{0} - I see the folder. Trying to write to a file." -f (get-date)
                   "Test" | Out-File "$Folder\Test.txt"                                  # verify that we can write to the folder 
                   if (Test-Path -Path "$Folder\Test.txt") {
                       "{0} - I see the file!. Ok to proceed. " -f (get-date)
                       remove-item -Path "$Folder\Test.txt"
                        $launch = $true                    # It's ok to run the program 
                   } Else {                  
                       "{0} - File not found. Something is wrong. " -f (get-date)
                   }  
                   $wait = $false
                   continue
               } else {
                   "{0} - I don't see the folder, testing the path." -f (get-date)
                   if (Test-Path $Folder) {
                       "{0} - I see the folder, but not the volume! Trying to write to a file." -f (get-date)
                       "Test" | Out-File "$Folder\Test.txt"                                  # verify that we can write to the folder 
                       if (Test-Path -Path "$Folder\Test.txt") {
                           "{0} - I see the file!. Ok to proceed. " -f (get-date)
                           remove-item -Path "$Folder\Test.txt"
                            $launch = $true                    # It's ok to run the program 
                       } Else {                  
                           "{0} - File not found. Something is wrong. " -f (get-date)
                       }  
                       $wait = $false
                       continue
                   }
               }
           }
           $count++
           if ($count -gt $limit) {
               "{0} - I give up. Here are the volumes that I saw." -f (get-date)
               Get-Volume | Format-Table
               $Wait = $false
               continue
           }
           "{0} - Sleeping, waiting for the {1} drive." -f (get-date), $DriveLetter
           start-sleep -Seconds 60                             # how long do we wait before retry 
       }
       if ($launch) {
           "{0} - Launching the program." -f (get-date)
    
           #------------------------------------------------------------------------------
           # Put your program and any arguments on the next line. 
           #------------------------------------------------------------------------------
           whoami.exe
    
       }
       "{0} - Terminating." -f (get-date)
       Stop-Transcript
    
    0 comments No comments

14 additional answers

Sort by: Most helpful
  1. 2021-12-20T07:55:31.407+00:00

    I remember when I started to work with computer, I learned writing .bat file. Today I still use .bat file if I want to do batch jobs in Windows OS. Your Powershell script is my first experience with it. I cannot understand what is wrong with running it.
    this is the result of your updated script when I run it with Task Scheduler, I copy your code in a file named SDLAutomation_starter.ps1 , you can see the command syntax I used in this log file:
    https://drive.google.com/file/d/1Jsq76MaQ40dDqVHUAuyXDUzb9XwNXbzK/view?usp=sharing

    As I said before the above script runs my program without informing us in above log file.

    I think there may be buffer do not flush to disk, so I use this command in the script:

    [Console]::Out.Flush() 
    

    but the resulting log file do not changed.
    so I think there maybe a problem with permissions, here is my permission configuration:

    PS C:\get-executionpolicy
    RemoteSigned
    

    Is it OK?
    When I run your script with PowerShell editor (ISE), then I get the result we expect:
    https://drive.google.com/file/d/1plCkXmfakGRbaeXGHqcJu8Cxv_nf84cZ/view?usp=sharing


  2. 2021-12-23T07:52:42.95+00:00

    I have observed the run result of these Task for 3 days, and I can confirm that running our program with this script is executeing correctly.
    So I satisty with this solution.
    thankyou MotoX80.

    0 comments No comments