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,635 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 32,911 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. MotoX80 32,911 Reputation points
    2021-12-07T14:04:18.433+00:00

    Does the program write to the C: drive or a network share? Maybe you just need to give all of the services some time to initialize before that program starts running.

    Set a delay in the startup trigger. (Since the program runs normally when you manually run it.)

    155693-capture.jpg

    0 comments No comments

  2. 2021-12-08T06:17:49.667+00:00

    Thank you for your answer.
    The task is writing to B:/Temp.A Ram drive holding Windows Temps.
    I have tried these so far, and not solved my problem:

    • Delay 30 second for startup trigger
    • I have experienced similar problem: running same task on other computer with different storage location(drives and directory) result in same exception, but random.
    • Choose FAT32 for storage which do not have NTFS security permissions
    0 comments No comments

  3. MotoX80 32,911 Reputation points
    2021-12-08T14:56:13.237+00:00

    The task is writing to B:/Temp.A Ram drive holding Windows Temps.

    What tool are you using to create the RAM drive? Does it generate any eventlog entries? Does it run as a service?

    Save the below script as a .ps1 file. Modify it to contain your program name and whatever log file you want to use. Configure the scheduled task to run Powershell.exe and execute the script. It will wait for B:\Temp to become available before it launches your program.

    Open a Powershell prompt and run Get-Volume to verify that your RAM drive shows up.

      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} volume." -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 
      } 
    
    
      ""
      while ($wait) {
          $vols = Get-Volume
          if (($vols).DriveLetter -match $DriveLetter) {        # do we see the drive letter 
              "{0} - I see the volume." -f (get-date) 
              New-Item -Path $Folder -ItemType Directory -ErrorAction SilentlyContinue                # Create the temp folder
              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 {
                  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." -f (get-date)
          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

  4. 2021-12-09T06:07:23.687+00:00

    Thanks, Now I can see a new way to solve my problem: . . . programing. The program which is suppose to run is developed by ourselves, so I can implement your logic inside of it.
    The problem I have described is a lab sample of the real problem on our server. On our server the exception rise not when triggers by startup but when executing this command:
    SCHTASKS /Run /TN "SDLAutomation2"
    The exceptions on the server and lab (my local computer) are similar. On the server exception happened even when the storage location was on hard disk.

    0 comments No comments