Announcement

Collapse
No announcement yet.

Create Scheduled Task via Command Line or in InnoSetup

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create Scheduled Task via Command Line or in InnoSetup

    I've used Task Scheduler to create a task that runs a program on demand with Admin privileges to bypass the Y/N response from the system that I would otherwise get when trying to run an EXE. I manually created the task using Task Scheduler. I can run the Task Scheduler task on demand, such as by creating a shortcut that points to that Task Schedule task.

    Today, I ran across someone saying that I can do that with InnoSetup, with a [RUN] entry that contains the same arguments as would be used when running schtasks.exe in a CMD window.

    So, to start with, I created a small app called myapp.exe, then opened a command prompt in the app folder and tried this:

    Code:
    schtasks.exe /Create /RL Highest /TN myapp /TR c:\temp\myapp.exe
    But, it gets a message saying the /SC option is missing, so I tried this:

    Code:
    schtasks.exe /Create /RL Highest /TN myapp /TR c:\temp\myapp.exe /SC Once
    But that in turn gets the error message that /ST (starttime) is required, so finally I've tried this:

    Code:
    schtasks.exe /Create /RL Highest /TN myapp /TR c:\temp\myapp.exe /SC Once /ST
    That gets the error that in invalid ST was used. But HELP says ST defaults to the current time is /ST is not specified.

    Has anyone had success using Task Scheduler with InnotSetup or manually in a CMD window?

    Two pages where I read about it:
    https://stackoverflow.com/questions/...ith-inno-setup
    http://tukeys.blogspot.com/2013/02/i...scheduled.html

    InnoSetup Help on RUN
    https://jrsoftware.org/ishelp/index....c=taskssection

    I can successfully create a task using this example from HELP at the command prompt so I know the method works in general, just not for the example I made up:

    Code:
    SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime /TR c:\windows\system32\freecell
    Once it seems to work at the command line prompt I'll try it in InnoSetup.

  • #2
    The last example above, the one that worked, used a specific scheduled time, whereas I want to run the app on demand.

    When creating a task manually using Task Scheduler, I'm allowed to choose ON DEMAND for running the task. But I don't see anything in HELP that lets me set the task as ON DEMAND via the command line. HELP only gives these schedule options:

    Valid schedule types: MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.

    Comment


    • #3
      Originally posted by Gary Beene View Post

      > schtasks.exe /Create /RL Highest /TN myapp /TR c:\temp\myapp.exe /SC Once /ST

      That gets the error that in invalid ST was used. But HELP says ST defaults to the current time is /ST is not specified.
      "ST is not specified" means that there is no /ST switch, not that the switch is there without a valid value!

      It also says this option is required with /SC ONCE.

      You are going to have to stuff a valid time in there if you use /SC ONCE



      Comment


      • #4
        Howdy, Stuart!

        That doesn't work for me. If I do put in a value for /ST that is later today, I get "Access is denied". I also get errors when I try an earlier time today.


        I found another potentially helpful page here ... https://serverfault.com/questions/56...runs-on-demand

        It suggests putting in an earlier time - but that fails for rme.

        It also suggests putting in a "dummy event". I tried their example and that fails for rme.

        I'm still playing with their examples to see if something will click.

        Comment


        • #5
          From that last link, the approach of creating a "dummy event" seems to be working now. Not sure why it didn't work before.

          Code:
          c:\temp>SCHTASKS /Create /TN TaskOnEvent /TR c:\temp\myapp.exe /SC ONEVENT /EC Application /MO *[System/EventID=777] /f
          SUCCESS: The scheduled task "TaskOnEvent" has successfully been created.
          I'll test it some more ...

          ... added ... but I'm not sure where the /EC and /SC values came from. I just used them as they were presented.

          Comment


          • #6
            In my last example, I had to add "/RL Highest" to enable running the task with highest privileges - the level needed to avoid the UAC Y/N popup.

            I'm toast for the night ... I'll play with it some more tomorrow.

            Comment


            • #7
              Now all you need is to generate a system event with EVENTCREATE with an ID of 777 to trigger the task

              (OK, I know you can run it on demand, but where's the challenge in that )


              Comment


              • #8
                Task Scheduler may not be needed to get rid of Y/N.
                Question: Does InnoSetup always show Y/N if the user is not logged in as admin?
                I have never had a user ask me about it so it is very possible they just don't mention it.

                [Setup]
                PrivilegesRequired=admin

                [Run]
                Filename: {app}\me.exe; Description: {cm:LaunchProgram,Widgetware}; Flags: shellexec runmaximized

                or (will need more code)
                [Code]
                ShellExec
                The world is full of apathy, but who cares?

                Comment


                • #9
                  Originally posted by Gary Beene View Post
                  From that last link, the approach of creating a "dummy event" seems to be working now. Not sure why it didn't work before.

                  Code:
                  c:\temp>SCHTASKS /Create /TN TaskOnEvent /TR c:\temp\myapp.exe /SC ONEVENT /EC Application /MO *[System/EventID=777] /f
                  SUCCESS: The scheduled task "TaskOnEvent" has successfully been created.
                  I'll test it some more ...

                  ... added ... but I'm not sure where the /EC and /SC values came from. I just used them as they were presented.
                  /SC ONEVENT mean run the task when a specified system event occurs.

                  /EC = Event Channel - Take a look at the Event Viewer - Windows Logs in Control Panel-Admin Tols. You will see a number of different "channels": Application, Security, Setup, System. You are telling Windows that your event 777 wil be generated/logged on the Application channel i.e. it will generated by an application.

                  Comment


                  • #10
                    Howdy, Stuart!
                    I take it to mean that a "777" is a fake event? That the person who responded in the article.knew it was fake and would never occur, leaving the task available for on-demand usage. I don't want to create the event, I just want to put a shortcut on the desktop and let my user click the shortcut whenever they want. The 777 just creates a place holder task for my app, which otherwise would be blocked by the UAC.

                    And, Howdy, Mike!
                    With InnoSetup, I see not the UAC Y/N but rather another popup saying that the downloaded setup EXE is risk and asks the user what to do. But one of the EXEs I install is a TeamViewer remote control EXE and it always gets a UAC Y/N ... unless I use Task Scheduler to create a task with "Highest Privileges". The Task Scheduler task allows my folks to bypass the UAC Y/N when running the TeamViewer remote control EXE that my setup app installs.

                    Comment


                    • #11
                      Thanks,
                      I am trying to get rid of "Ready to Install" page.
                      I may switch to your method.

                      The world is full of apathy, but who cares?

                      Comment


                      • #12
                        Maybe you can turn off Smart Screen for your users
                        https://www.howtogeek.com/75356/how-...-in-windows-8/


                        or a registry entry
                        https://www.winhelponline.com/blog/bypass-smartscreen-even-if-its-enabled-through-group-policy/


                        Is it possible to do a silent install without using the /SILENT or /VERYSILENT command-line parameters?
                        No, nor is such a feature planned (it would be abused). If it is your intention to keep user interaction to a minimum, use the Disable* [Setup] section directives.

                        Code signing doesn't seem like an option due to cost and some have said a reputation has to be established
                        The world is full of apathy, but who cares?

                        Comment


                        • #13
                          Looks like 777 is a pretty safe event to trigger, it's usually an Information Event after an application crash dump.
                          A couple of references to Event 777:

                          Event 777
                          This event is logged when Application image succesfully dumped.
                          Resolution
                          This is a normal condition. No further action is required.


                          Source
                          COM+
                          Level
                          Information

                          Description
                          Application image successfully dumped. <dump file>
                          Server Application ID: <ID>
                          Server Application Instance ID: <ID>
                          Server Application Name: <name>

                          Comment


                          • #14
                            Howdy Mike!

                            Maybe you can turn off Smart Screen for your users
                            I was looking at the SmartScreen and apparently it only applies to downloads through Edge or from the Windows App Store. Is that your understanding as well?

                            My users download from garybeene.com and typically use Chrome. I don't recall seeing any "Smart Screen" nomenclature on popup windows.

                            Comment


                            • #15
                              I see things have changed. There used to be a setting in Internet options.

                              https://www.howtogeek.com/75356/how-...-in-windows-8/

                              I did some more reading on InnoSetup and I can't get rid of the final screen because the author requires at least 1-screen.

                              I am curious if you already have software on the users machines or if this is for a first-time install.
                              If you have software on the machine already would definitely make it easier bypassing the browser.
                              Then again, not sure since I haven't done any of this without a user being able to click something.

                              You might be interested in a service so nothing ever needs to be clicked for transferring files.
                              The world is full of apathy, but who cares?

                              Comment


                              • #16
                                Just food for thought.
                                Files can be sent back and forth in the background using the SQLitening service (see slGetFile,slPutFile.)
                                The SQLitening service includes source code in PowerBASIC.
                                The world is full of apathy, but who cares?

                                Comment


                                • #17
                                  Howdy, Mike!
                                  This is for a first time install.

                                  For updates, I have built in API/TCP procedures to get new files or to update existing files. I don't do automatic updates. Users must initiate an update within my apps. I use the same technique for all of my gbApps.


                                  Comment


                                  • #18
                                    Worth a read, methinks...



                                    Where you will find...

                                    This section contains code examples that illustrate how the Task Scheduler API is used and XML examples that show how tasks are defined in the Task Scheduler schema. Most of these examples are stand-alone code that can be run independently, or pasted into a larger application and modified to the requirements of the application.
                                    Now, how does this address your limitation in the title, " Create Scheduled Task via Command Line or in InnoSetup???"

                                    Well, you write your own command line program.

                                    However, if you are planning on using this as part of an install procedure using Inno Setup. I'd write it as a FUNCTION and export it from a Dynamic Link Library so you can call it right from your Inno Script as demonstrated here....

                                    Inno Setup:Commented Installation Script June 8 2003

                                    Let me check if that shows calling an external function ... no, it does not. Phooey.

                                    OK, let me be nice guy and add a script which does do that to that source code posting......

                                    Ok, I added another script which has the call of the external.....BUT.. getting "paste" to keep the indents in the formatting was a dog... So I attached the file 'as is' except for the suffix.

                                    That script shows the required Inno Setup "[FILES]" entries as well as the Pascal source code you need to get your function(s) called during the setup.

                                    MCM
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      getting "paste" to keep the indents in the formatting was a dog... So I attached the file 'as is' except for the suffix.
                                      Check Adam's post.
                                      I'm a bit behind actually posting information on this, but several have made me aware of the fact that pasted source code is losing it's formatting on here. I have reported this to vBulletin - and they are aware of and have acknowledged the bug, but have given no further feedback. If you will switch to source mode, and paste
                                      Rod
                                      In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                                      Comment


                                      • #20
                                        Check Adam's post.
                                        I will play with that formatting tip, Rodney (and Adam's linked post) .

                                        Hmm... not working (yet) ?

                                        One problem may be there is now an embedded "Left square bracket, CODE, right square bracket" within the Inno Setup Script... which of course IS a vBulletin "magic header" and may be messing up all kinds of stuff.

                                        I think I shall use the test forum.. and then see if I can move the post to where I want it. I think I get a day or two to edit it.




                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X