Export/Import Scheduled Tasks in bulk

Page 2 of 3 FirstFirst 123 LastLast

  1. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #11

    A summary


    kitpzyxmsir,

    Your second post indicated that you have already dealt with the job of [bulk] backing up of tasks so I will not address that any further.

    I do not bulk restore tasks so all I can offer are guides to the viable approaches that you might choose
    Try3 said:
    I have not done any mass importation but would look to the SchTasks command for that.
    SchTasks /Create /?
    schtasks - SS64
    schtasks MSDocs
    or I'd examine PowerShell's capabilities in this respect
    together with the warnings that
    Try3 said:
    If you merely copy them back into C:\Windows\System32\Tasks on the new computer then TS will detect them as having been tampered with and it will refuse to run them.
    and
    Try3 said:
    With some exceptions, importing the task definition within TS on another computer requires that the whole <UserId> line of the backed up task definition be deleted first. I just do this manually within Notepad.
    - This applies to the tasks you have created yourself.
    - I've transferred task run by the System 'user' without having had to remove that line.
    You'll have to deal with the issue of user accounts within task definitions one way or another.


    That's all I have to contribute,
    Best of luck,
    Denis
      My Computer


  2. Posts : 168
    10 (1909)
       #12

    Try3 said:
    Task scheduler?
    They need to be imported within TS or by using SchTask*** commands. If you merely copy them back into C:\Windows\System32\Tasks on the new computer then TS will detect them as having been tampered with and it will refuse to run them.
    *** Or the PowerShell equivalents - see ScheduledTasks - MSDocs



    As I said above,

    - This applies to the tasks you have created yourself.
    - I've transferred task run by the System 'user' without having had to remove that line.


    Denis
    So there's no convenient way to copy my task as they are with folder structure preserved? Can't I get windows to treat them as valid by some means, like also importing some registry keys (I imagine).
      My Computer


  3. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #13

    avada said:
    So there's no convenient way to copy my task as they are with folder structure preserved?
    SchTasks allows you to import them into specific folders of your choosing. See the links I posted earlier.


    avada said:
    Can't I get windows to treat them as valid by some means, like also importing some registry keys (I imagine).
    I have never seen any such method.


    I have also replied to a TS question of yours in the TS tutorial thread.


    Denis
      My Computer


  4. Posts : 168
    10 (1909)
       #14

    Try3 said:
    SchTasks allows you to import them into specific folders of your choosing. See the links I posted earlier.



    I have never seen any such method.


    I have also replied to a TS question of yours in the TS tutorial thread.


    Denis
    Thanks. I'll start trying.
    It wouldn't be such a bother if TS allowed moving tasks in its interface
      My Computer


  5. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #15

    Try3 said:
    SchTasks allows you to import them into specific folders of your choosing. See the links I posted earlier.
    I know I have imported into a specific folder and have been checking my notes to check the syntax but I cannot find what I wanted.
    I think the syntax was merely in the /TN bit - instead of
    Code:
    /TN TaskName
    it was, I think,
    Code:
    /TN FolderName\TaskName
    That is certainly consistent with how an exported task from a folder would look. If, just for example, you go to the TS Task library folder \Microsoft\Windows\Chkdsk and export the ProactiveScan task from there, its exported .xml file contains the line <URI>\Microsoft\Windows\Chkdsk\ProactiveScan</URI>, i.e. Foldername\TaskName, whereas a task in the highest level of the TS Task library would have the line <URI>\TaskName</URI>

    What a fool I am at times. Knowing that I had done this in the past, I was checking back through my own notes. I have only just noticed that Brink used a SchTasks xml import into a specific folder example in Option 2 of the TS tutorial that both of us recently posted in.


    Best of luck,
    Denis
    Last edited by Try3; 19 Nov 2022 at 11:59.
      My Computer


  6. Posts : 168
    10 (1909)
       #16

    hdmi said:
    To copy all the tasks to your folder E:\Backup\My Tasks
    Code:
    @echo off
    set d=E:\Backup\My Tasks
    chcp 65001>nul
    copy \\?\%Windir%\System32\Tasks\*.* "\\?\%d%"
    (You could decide to simply copy these with File Explorer instead, but that won't work if one or more tasks have a name that ends with a period [.] character, as File Explorer refuses to recognize filenames that end with a period even though such filenames are nonetheless valid NTFS filenames... I know it's funny, but you can verify this yourself by creating a new task named test. if you don't believe.)

    Next, on the other computer, assuming that your folder to which you have copied the tasks is now F:\Backup\My Tasks
    Code:
    @echo off
    set d=F:\Backup\My Tasks
    chcp 65001>nul
    for /f "usebackq delims=|" %%f in (`dir /b "\\?\%d%"`) do (
      schtasks /create /tn "%%~f" /xml "\\?\%d%\%%~f"
    )
    del "\\?\%d%\*.*"
    (The last command will delete all the files from your folder if you choose to confirm, File Explorer can't delete a file if the filename ends with a period so, to delete a file F:\Backup\My Tasks\test. you could run del "\\?\F:\Backup\My Tasks\test." )
    Hmm.. I tried modifying this to my needs:
    Code:
    @echo off
    set d=b:\OS\tasks\Saját\
    chcp 65001>nul
    for /f "usebackq delims=|" %%f in (`dir /b "\\?\%d%"`) do (
      schtasks /create /tn "Saját\%%~f" /xml "\\?\%d%\%%~f"
    )
    del "\\?\%d%\*.*"
    But all I got was "ERROR: A fájlnév, a könyvtárnév vagy a kötetcímke szintaxisa nem megfelelő." a bunch of times.
    Which translates to something like "Error: The syntax of the filename, directory name or volume label is inappropriate."

    - - - Updated - - -

    Well, I modified it based on the output. Not sure what the "\\?" was meant to do, but it was added prefix to the path so the command got "\\?\b:\OS\tasks\Saját" which is invalid of course
    Code:
    chcp 65001
    set d=b:\OS\tasks\Saját\
    
    for /f "usebackq delims=|" %%f in (`dir /b "\\?\%d%"`) do (
      schtasks /create /tn "Saját\%%~f" /xml "%d%\%%~f"
    )
    So it fails with a bunch of different errors. Access denied, or "A fióknevek és a biztonsági azonosítók között nem jött létre egymáshoz rendelés." ("There is no mapping between account names and security IDs." by DeepL)
      My Computer


  7. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #17

    It's entirely up to you but I am only interested in backing up the tasks I have created and I know which folders they are in.
    I use RoboCopy commands to copy
    - tasks from the main TS Task library into my TaskBackup folder
    - tasks from the MyFolder I created for some of my own tasks into my TaskBackup\MyFolder folder.
    I also include RoboCopy switches to skip tasks created by applications e.g. /XF "C:\Windows\System32\Tasks\Intel PTT EK Recertification"


    Denis
      My Computer


  8. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #18

    What a fool I am at times. Knowing that I had done this in the past, I was checking back through my own notes.

    I have only just noticed that Brink used a SchTasks xml import into a specific folder example in Option 2 of the TS tutorial that both of us recently posted in.

    But do note what I said in that thread about deleting the whole line<UserId>...</UserId> because that avoids your having to mess about with specifying users & passwords. The task is imported for the user who is running the command.



    And thanks for the rep,
    Best of luck,
    Denis
      My Computer


  9. Posts : 168
    10 (1909)
       #19

    This seems to have worked if anyone's interested:
    Code:
    chcp 65001
    set d=b:\OS\tasks\Saját\
    set "u=%computername%\%username%"
    set "psCommand=powershell -Command "$password = read-host 'Please enter the run as password for %u%' -AsSecureString ; ^
        $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password); ^
            [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
    for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
    for /f "usebackq delims=|" %%f in (`dir /b "\\?\%d%"`) do (
      schtasks /create /tn "\Saját\%%~f" /ru "%u%" /rp "%password%" /xml "%d%\%%~f"
    )
    I still don't know why the \\?\ was there. Or what is the ">nul" part is supposed to do so I removed them.
    The error about account names and security identification went away with the username/password now added.
    The access denied part was (unsurprisingly) because of the lacking elevated rights originally.
    Also one of the access denied errors was for a folder, because I have a subfolder for my tasks. So I guess I'll have to modify the script for this sub-folder. (easier than modifying it to work recursively, and create TS folders accordingly)

    PS: I ran it in Powershell.

    - - - Updated - - -

    Uh-oh. Something went very wrong.

    The programs started TS are running but are invisible to me. No UI, or notification area icons.
    And when I start them manually another instance is started, which they are specifically set not to do, or don't allow by default.
    For the two different instances Process Explorer shows my username, identical between to the two instances, also the SID. But it's as if they are running under a different account. Not clue what's happening.

    - - - Updated - - -

    I compared the new task in system32/tasks and the backup of the old one:
    Export/Import Scheduled Tasks in bulk-ts-diff.png
    I see that the original had an SID as a user ID the imported one merely has my computer\username.
    Is this the big difference?
    (Ugh. Got fed up and imported all of them manually. What a waste of time this was...)
    Last edited by avada; 19 Nov 2022 at 13:36.
      My Computer


  10. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #20

    It is normal for the task definition itself to show the username but the exported xml to show the SID.

    The difference that strikes me is that you have set the left-hand one to run whether or not the user was logged in.
    If so, you might well not see any interface for the task as it runs. The interface would only be shown to the not-logged in user, who has no interface because they are not logged in.
    I have not played around with 'Run whether user is logged in or not' for years so my memories of it are extremely sketchy.

    All the best,
    Denis
      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 13:03.
Find Us




Windows 10 Forums