Windows 10 Scheduled Task only runs batch file if I am logged on

Page 1 of 3 123 LastLast

  1. Posts : 14
    Windows 10
       #1

    Windows 10 Scheduled Task only runs batch file if I am logged on


    Windows version: 10

    I wrote a batch file that will update files in one of my directories. The batch script references a Java class app I wrote. The class works on its own; the batch script works on its own. I created a Windows Scheduled Task to run the batch script every day at 9am. If I am logged in on my laptop, the scheduled task runs, and the files are updated. If I am not logged in on my laptop, the scheduled task appears to run (according to the history), but the files are never updated. If I manually run the scheduled task, it runs, and the files are updated. I made sure to perform every step that I read I am supposed to do:

    1. I created the task with the user "NT AUTHORITY\SYSTEM"
    2. I clicked "Run if the user is logged in or not"
    3. I added SYSTEM and myself as users under Security Policy > Security Settings > Local Policies > User Rights Assignment > Log on as a batch job
    4. I ensured that the batch script would go to the directory where the batch script resides before running the remainder of the script


    Windows 10 Scheduled Task only runs batch file if I am logged on-screen.jpg

    Windows 10 Scheduled Task only runs batch file if I am logged on-screen2.jpg

    Windows 10 Scheduled Task only runs batch file if I am logged on-screen3.jpg

    The batch script:

    Code:
    ECHO Running DandyLabsBlogEntryRetriever..
    
    SET myPath=C:\users\phill\OneDrive\Desktop
    SET classes=%myPath%\classes
    
    CD %myPath%\batch
    
    "C:\Program Files\Java\jdk-14.0.1\bin\java" -cp "%classes%;%myPath%/jar/commons-io-2.11.0.jar;%myPath%/jar/mysql-connector-java-8.0.19.jar" com.dandylabs.DandyLabsBlogEntryRetriever && (
     (call)
    ) || (
     (call)
    )
    I don't know what else to do, and I have done extensive research into this issue to no avail. Is there something else I would need to do? Please advise, thanks
      My Computer


  2. Posts : 8,132
    windows 10
       #2

    Run As system
      My Computer


  3. Posts : 14
    Windows 10
    Thread Starter
       #3

    Samuria said:
    Run As system
    I am running this task as System, yet the same behavior occurs.
      My Computer


  4. Posts : 756
    Windows 10/11
       #4

    ppowell777 said:
    I don't know what else to do, and I have done extensive research into this issue to no avail. Is there something else I would need to do? Please advise, thanks
    Although SYSTEM should have no issue accessing files from any location, I'm still a bit concerned about running the script from C:\users\phill\OneDrive\Desktop. Maybe try it from a location such as C:\Scripts or C:\Tools.

    To troubleshoot, I'd recommend opening a Cmd prompt as SYSTEM and manually running the script to see if you get any error messages. One way to do that is to use the option "Cmd here as TrustedInstaller" from this tool:

    RightClickTools | Add a Set of Powerful Tools to the Windows Explorer Context Menu
      My Computer


  5. Posts : 829
    Windows 7
       #5

    The other consideration is SYSTEM as a non-interactive profile, may not inherit the full environment variables a normal user or the Administrator account has. You should try dumping a list of environment variables (from the script into a file), and confirm everything is there for Java to run.
      My Computer


  6. Posts : 14
    Windows 10
    Thread Starter
       #6

    LesFerch said:
    Although SYSTEM should have no issue accessing files from any location, I'm still a bit concerned about running the script from C:\users\phill\OneDrive\Desktop. Maybe try it from a location such as C:\Scripts or C:\Tools.

    To troubleshoot, I'd recommend opening a Cmd prompt as SYSTEM and manually running the script to see if you get any error messages. One way to do that is to use the option "Cmd here as TrustedInstaller" from this tool:

    RightClickTools | Add a Set of Powerful Tools to the Windows Explorer Context Menu
    So I did the following:

    1. Created C:\Tools
    2. Copied my batch script into C:\Tools
    3. Downloaded and installed RightTools.exe
    4. Tested via going to folder > Right Click > Run as Trusted Installer > the batch file - which successfully ran
    5. Rescheduled the task for 3pm EST


    I closed up my laptop and left for the afternoon. Returning at around 7:30pm, I reopened my laptop, logged in, and the scheduled task never ran. The task didn't even start, according to the Scheduled Task history. However, at 7:43pm, while I was still on my laptop doing unrelated tasks, the task ran on its own and was successful.

    It appears that the scheduled task will only run if I am logged in, even if the task is located at C:\Tools
      My Computer


  7. Posts : 756
    Windows 10/11
       #7

    It's probably an environment variable issue as @garlin mentioned. The option "Cmd here as TrustedInstaller" inherits the user environment, whereas the SYSTEM scheduled task does not. It may be as simple as changing one or more Java user path entries to the System path.
      My Computer


  8. Posts : 14
    Windows 10
    Thread Starter
       #8

    LesFerch said:
    It's probably an environment variable issue as @garlin mentioned. The option "Cmd here as TrustedInstaller" inherits the user environment, whereas the SYSTEM scheduled task does not. It may be as simple as changing one or more Java user path entries to the System path.
    I don't understand. Do you mean to add "C:\Windows\System32" and "C:\Windows\SysWOW64" to the Java class path? I'm not sure what you mean
      My Computer


  9. Posts : 829
    Windows 7
       #9

    There's one overlooked environmental issue:
    Code:
    SET myPath=C:\users\phill\OneDrive\Desktop
    SET classes=%myPath%\classes
    While SYSTEM has unrestricted access to all local files, it depends on how your OneDrive is configured for local caching. You said it never runs when you're not logged on. It doesn't matter where the batch script resides, it's all the referenced files this java instance touches.

    If you don't have OneDrive enabled to keep a local copy of files (available if you're not logged on), or logon to Windows so it will force a folder resync; then storing files under that path is going to cause problems without your logon.
      My Computer


  10. Posts : 14
    Windows 10
    Thread Starter
       #10

    garlin said:
    There's one overlooked environmental issue:
    Code:
    SET myPath=C:\users\phill\OneDrive\Desktop
    SET classes=%myPath%\classes
    While SYSTEM has unrestricted access to all local files, it depends on how your OneDrive is configured for local caching. You said it never runs when you're not logged on. It doesn't matter where the batch script resides, it's all the referenced files this java instance touches.

    If you don't have OneDrive enabled to keep a local copy of files (available if you're not logged on), or logon to Windows so it will force a folder resync; then storing files under that path is going to cause problems without your logon.
    Currently my batch script looks like this and resides in C:\Tools:

    Code:
    ECHO Running DandyLabsBlogEntryRetriever..
    
    SET myPath=C:\Tools
    SET myClassPath=C:\users\phill\OneDrive\Desktop
    SET classes=%myClassPath%\classes
    
    CD %myPath%
    
    "C:\Program Files\Java\jdk-14.0.1\bin\java" -cp "%classes%;%myClassPath%/jar/commons-io-2.11.0.jar;%myClassPath%/jar/mysql-connector-java-8.0.19.jar" com.dandylabs.DandyLabsBlogEntryRetriever && (
     (call)
    ) || (
     (call)
    )
    I will have to figure out how to get OneDrive enabled to keep a local copy of files; that I do not know how to do
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 16:19.
Find Us




Windows 10 Forums