No announcement yet.

Running a Task Scheduler Shortcut

  • Filter
  • Time
  • Show
Clear All
new posts

    Running a Task Scheduler Shortcut

    One of the techniques for preventing UAC from requiring a user "Yes/No" response is to create a scheduled task for an app, then start the app using a shortcut to that scheduled task - as discussed here.

    I've tried the approach and manually double-clicking on the shortcut works just fine (no UAC popup). But I'd like to open the EXE from within my PowerBASIC app by calling the shortcut to the Task Scheduler scheduled task.

    I've used code that dereferences a *.lnk file so that I can SHELL to the original EXE, but that code doesn't apply to a scheduled task shortcut because the shortcut target is a Task Scheduler file, not an EXE. Plus, avoidance of the UAC requires going through Task Scheduler.

    Has anyone been able to start an app from a PowerBASIC program by using a shortcut to a Task Scheduler task for that app?

    I see that Jose has an include file called "". I'll go nose around that!


      This link gave me the hint on what to look for in Jose's include files. The declaration "As New TaskService()" caught my eye.


        If I know the Task Scheduler taskname, that it would appear I can call Task Scheduler by code to run that task. No shortcut needed? Learning as I go here.


          Finding lots of stuff posted by Jose ... here, for example. Digging ... looking for an example that runs a scheduled task ...


            There is always the shell method:

            SCHTASKS /parameter [arguments]

            Enables an administrator to create, delete, query, change, run and
            end scheduled tasks on a local or remote system.

            Parameter List:
            /Create Creates a new scheduled task.

            /Delete Deletes the scheduled task(s).

            /Query Displays all scheduled tasks.

            /Change Changes the properties of scheduled task.

            /Run Runs the scheduled task on demand.

            /End Stops the currently running scheduled task.

            /ShowSid Shows the security identifier corresponding to a scheduled task name.

            /? Displays this help message.

            SCHTASKS /?
            SCHTASKS /Run /?
            SCHTASKS /End /?
            SCHTASKS /Create /?
            SCHTASKS /Delete /?
            SCHTASKS /Query /?
            SCHTASKS /Change /?
            SCHTASKS /ShowSid /?

            A bit off topic, but one of my favorites to automatically create restore points.
            By default, System Restore automatically creates a restore point once per week and also before major events like an app or driver installation.


              Hello, Mike!

              Yes, that definitely works and does avoid the UAC window. Here's code I'm using on a scheduled task called "TeamViewerElevation".

              #Compile Exe
              #Include ""
              Function PBMain() As Long
                 Local iResult As Long
                 iResult = Shell("C:\Windows\System32\schtasks.exe /RUN /TN  TeamViewerElevation",0)  '0 to keep schtasks.exe from flickering
              End Function
              I was just wondering if there was a non-SHELL approach as well. If I were going to run a lot of Task Scheduler commands, I'd rather not be SHELLing out each time. No technical reason, I suppose, just a preference.


                Has anyone been able to start an app from a PowerBASIC program by using a shortcut to a Task Scheduler task for that app?
                Why would anyone even try that? If you can start something thru task scheduler, certainly you can start it from your PB program with SHELL or CreateProcess() or ShellExecuteEx().

                What am I missing here?

                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]


                  Imagination? Curiousity? Unwillingness to read the first post? The thing about knowledge is that you never know when you might need it in the future. Are you saying that you've never tried to learn something because you didn't have an immediate need for it? If so, that would be a sad story.


                    But... I was curious.

                    I was curious why you'd insert a middleman (Task Scheduler) when you could have gone direct.

                    As far as I'm concerned, the more steps you insert into any process simply increases the number of potential failure points. But I'm kind of surprised a retired engineer would forget that.

                    Were you, say, a retired Chicago alderman instead, NOW I can you cutting in a few extra steps and relati^H^H^H^H^H^H... er, personnel.

                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]


                      Well, perhaps then you can explain the SHELL suggestion. As best I know, SHELLing an app won't bypass the UAC, which was the goal I mentioned in post #1.

                      Are you saying that you know how to use SHELL to bypass UAC? I'd definitely like to know how to do that. Can you post an example?


                        I don't know how to bypass UAC, using SHELL or anything else; and if I did, I certainly would not be sharing that info. UAC is present to enforce security.

                        With proper user credentials UAC is not any kind of issue at all.

                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]


                          I have to agree with Michael here. Bypassing UAC is ... erhm, how to put that politely? .... suboptimal. Except lazy users and malicious intentions, I can't think of a valid reason to bypass UAC.