Importing Scheduled Tasks

Discussion in 'Scripting' started by tnx, Jul 11, 2021.

  1. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    I have been messing about making some scheduled tasks on my main PC.
    I want to import these tasks onto new installs.

    I have this script
    Code:
    setlocal disabledelayedexpansion
    
    for %%e in ("%~dp0*.xml") do (
      schtasks /create /tn "%%~ne" /xml "%%~e"
    )
    
    pause
    After a new install I run the script with the exported .xml files and I just get errors relating to the User ID and name.
    I can import these manually but there are 13 tasks and its a bit of a pain.

    Not right up on the Task Scheduler, in fact first time I have messed with it.

    Two things strike me.

    Either how I made the tasks in the first place or the script I am using to import the tasks with.

    So..

    How can I make a task on one PC, export it then import it through command prompt.

    Is there a setting when making the task so it could be any user and or any PC ?

    Hope this makes sense.

    Any help would be great.

    The tasks I have made relate to DISM. I fancied not having to right click on the .cmd file, way to much trouble.

    I wanted to be able to make a shortcut, double click on the shortcut and run the .cmd without UAC interaction.
    Creating tasks in Task Scheduler was the only way I found to do it.
     
  2. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    Well I finally figure it. Why it wouldn't import the scheduled tasks.

    Bit obvious really.

    The user and ID's were not the same.

    I ran through the command prompt
    This gives you the relative information of both PC's.

    I amended the .xml file exported from PC#1 to have the user and ID's of PC#2 and the scheduled task imported and worked a treat..

    I suppose after a new install all I would have to do is get the user and ID's of the fresh install. Amend all 13 scheduled tasks to have the updated info and then import them.

    I recon I could find a way to automate the process but it does sound rather long winded.

    I could just keep using my existing DISM commands using Right Click > Run As Admin...

    Could be fun trying to automate it though... Summet to do..
     
  3. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    Well Notepad++ made short work of that
     
  4. acer-5100

    acer-5100 MDL Guru

    Dec 8, 2018
    3,645
    2,620
    120
    I can add that there is no point exporting, although is the official way

    Just go to \windows\system32\tasks you will find a bunch of files with no extension.

    They are just xml files with no extension. So you can just copy and rename the files instead of exporting them one by one.

    For import you must follow the official procedure which you have already figured
     
  5. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    What I have done is exported them one by one making sure to keep my naming system consistent.

    So now I have a bunch of 13 .xml files.
    I will keep these in a safe place.

    So using my $OEM% folder structure when I do a fresh install my DISM folder structure is automatically there when I want it. Been using this method for many years now.
    On my USB installer I have a folder called "Extras" where I keep files need to me after an install. A certain driver, etc etc. Now it will hold these .xml files.

    I will simply find the PC name, user and SID's.

    Using Notepadd++ I will open all 13 .xml files and use it to find and replace all instances in all open files to change the User name etc etc.
    In a flash all 13 .xml files will be updated and then using my .cmd I will import them all into my sub folder within Task Scheduler..

    Sounds like a lot of work but now the hard work is done each new install wont be so much work...

    Now a simple double click of a shortcut will execute my chose DISM command and run without any interaction from me..

    Plus, its been fun messing..
     
  6. acer-5100

    acer-5100 MDL Guru

    Dec 8, 2018
    3,645
    2,620
    120
    Naming is consistent, just the xml extensions are missing

    Sure, once I had to replace a sting in a 500+ files source three.

    Just searched all files with Agent Ransack opened all of them with NPP and replaced thousands of the occurrences with two clicks.

    If I had to use the stock search and notepad it was a month of work :D
     
  7. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    Just for the laugh I am on with making a nice little GUI to automate amending the .xml files.

    Stage one was to figure out how to display the PC user and the SID numbers..
    Stage one complete, didn't take too long. Works a treat.

    Lets see if I can get my GUI to open a .xml, find the user and SID info.

    This is gunna be fun..

    Using Autoplay Media Studio... FYI
     
  8. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    Just to update.

    Found a bit of time to mess and I have now got a basic GUI working to amend a scheduled task .xml document inputting the new users details so the "Task Scheduler" can import it without any errors. With just one click of a mouse..

    Just to tart it up a bit...:cool:
     
  9. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    Got it all finished.

    Looks good, works a treat..

    [​IMG]