Starting an app in task scheduler as admin


  1. Posts : 1
    Windows 10
       #1

    Starting an app in task scheduler as admin


    I have an EXE that runs an agent that is used to connect to QuickBooks Desktop on a Windows 10 computer. The requirements are that the agent EXE and the QuickBooks EXE are the same bitness(x64) and are opened using the same username.

    The agent has a UI EXE that when launched as admin pops up a window. From there I can confirm that the agent is working correctly. Then I can launch QUickBooks as administrator and the agent connects to QuickBooks successfully.

    This connection is all part of a replication that would happen after hours, so it would need to run via scheduled jobs.

    Without needing any info about the agent, the issue is when I try to use the task scheduler and start the agent in the job (as admin), it will work fine if I check 'Run only when user is logged in' This opens the UI EXE just as if you double click it. If I check 'run whether the user is logged in or not', it opens the UI EXE in the background. I can confirm the agent is functioning correctly, but it wont connect to QuickBooks. the only difference is running in the background.

    My question is - are permissions changed when an app is opened with 'run whether the user is logged in or not' vs. 'Run only when user is logged in'? That is the only difference I am seeing.

    My goal is to have the task scheduler run these jobs in the middle of the night so the replication can happen off hours. Hence, all permissions and opening of files needs to be handled through the task scheduler.

    There is also the possibility to run these agent EXEs as a service. If I run the same EXE as a service as admin, its the same result as running in task scheduler as 'run whether the user is logged in or not'

    Would it be better to just execute a BAT file from the task scheduler that opens the EXE UI?
      My Computer


  2. Posts : 4,187
    Windows 11 Pro, 22H2
       #2

    Welcome to TenForums!

    I was just experimenting with something similar. I have a new mini PC that has a built-in screen. However, when doing a clean install on that system, the screen control software would not run until I logged on so I ended up creating a task in task scheduler to launch the software.

    In experimenting I found a couple of things useful:

    1) I made a small batch file and launched it rather than my screen control software to see how it was behaving.

    Here is the batch file:

    Code:
    @echo off
    cd /d %~dp0
    cls
    
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Check to see if this batch file is being run as Administrator. Log the results ::
    :: to a file called "results.txt" along with the date and time.                   ::
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    
    NET SESSION >NUL 2>&1
    IF %ERRORLEVEL% EQU 0 (
        ECHO %DATE% %TIME%: Ran as administrator >> results.txt
    ) ELSE (
        ECHO %DATE% %TIME%: Not run as administrator >> results.txt
    )
    
    
    ::::::::::::::::::::::::::::::::::::::::::::::::
    :: End Routine to check if being run as Admin ::
    ::::::::::::::::::::::::::::::::::::::::::::::::
    To use this, simply place it on your desktop and schedule it to be run with task scheduler. Have available a watch or other time source that is in agreement with the time on your computer. Reboot. Note the time that you hit the logon screen. Wait about a minute. Log on. On your desktop will be a file called results.txt. It will contain the time the batch file was run and whether it was run as an admin or not. If the time closely matches when you first arrived at the logon screen, then it run before you physically logged on.

    2) This step is the magic sauce.

    IMPORTANT: I am running Windows 11. I don't have a Windows 10 machine in front of me, but Bing Chat is telling this optin is available in Windows 10 as well. See the screenshot below for instructions on where to find this setting.

    There is a setting in Settings called Use my sign-in info to automatically finish setting up after an update. Turn this ON. (It's on be default in Windows 11). By turning this option on, you won't see anything, but at the login screen, the system is actually logging in as you with a token. This allows the task you scheduled to run as if you were logged in.

    Use the batch file above to test your task scheduler settings. You should be able to get it to behave the way you want. In my case I simply use the option to run with highest privileges and supply my username and password and it runs flawlessly.

    Starting an app in task scheduler as admin-image1.jpg
      My Computers


 

  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 03:13.
Find Us




Windows 10 Forums