Commit deb7f5e3 authored by Yuanle Song's avatar Yuanle Song
Browse files

install scheduled tasks when installing.

parent e417cae4
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -6,7 +6,7 @@
    <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
    <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
    <RootNamespace>Mbackup</RootNamespace>
    <RootNamespace>Mbackup</RootNamespace>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <Version>0.3.0.0</Version>
    <Version>0.4.5.0</Version>
  </PropertyGroup>
  </PropertyGroup>


  <ItemGroup>
  <ItemGroup>
+35 −3
Original line number Original line Diff line number Diff line
<?xml version="1.0"?>
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" UpgradeCode="3030B91E-5E3E-4151-9A69-B53B72690430" Version="$(var.Version)" Language="1033" Name="mbackup" Manufacturer="Yuanle Song">
  <Product Id="*" UpgradeCode="3030B91E-5E3E-4151-9A69-B53B72690430" Version="$(var.Version)" Language="1033" Name="mbackup" Manufacturer="Yuanle Song">
    <Package InstallerVersion="300" Compressed="yes"/>
    <Package InstallScope="perMachine" InstallerVersion="300" Compressed="yes"/>
    <Media Id="1" Cabinet="mbackup.cab" EmbedCab="yes" />
    <Media Id="1" Cabinet="mbackup.cab" EmbedCab="yes" />


    <MajorUpgrade AllowDowngrades="yes"/>
    <MajorUpgrade AllowDowngrades="yes"/>
@@ -50,7 +50,7 @@
                Description="Backup your computer using rsync"
                Description="Backup your computer using rsync"
                Target="[!filE3FFB5E42FD6DDB7AD945F29409779F0]"
                Target="[!filE3FFB5E42FD6DDB7AD945F29409779F0]"
                WorkingDirectory="MBACKUP_PROGRAM_FILES"/>
                WorkingDirectory="MBACKUP_PROGRAM_FILES"/>
            <RemoveFolder Id="DesktopShortcut" On="uninstall"/>
            <RemoveFolder Id="MbackupDesktopShortcut" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\mbackup\desktopshortcuts" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
            <RegistryValue Root="HKCU" Key="Software\mbackup\desktopshortcuts" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
        </Component>
        </Component>
    </DirectoryRef>
    </DirectoryRef>
@@ -77,11 +77,43 @@
                      Description="mbackup local-exclude.txt file"
                      Description="mbackup local-exclude.txt file"
                      Target="[!local_exclude.txt]"
                      Target="[!local_exclude.txt]"
                      WorkingDirectory="MBACKUP_PROGRAM_FILES"/>
                      WorkingDirectory="MBACKUP_PROGRAM_FILES"/>
            <RemoveFolder Id="MBACKUP_START_MENU_DIR" On="uninstall"/>
            <RemoveFolder Id="mbackup_start_menu_dir" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\mbackup\startmenushortcuts" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
            <RegistryValue Root="HKCU" Key="Software\mbackup\startmenushortcuts" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
        </Component>
        </Component>
    </DirectoryRef>
    </DirectoryRef>


    <InstallExecuteSequence>
        <Custom Action="CreateScheduledTaskLogon" Before='InstallFinalize'>NOT Installed</Custom>
        <Custom Action="RemoveScheduledTaskLogon" Before="RemoveFiles">Installed</Custom>
        <Custom Action="CreateScheduledTaskInterval" Before='InstallFinalize'>NOT Installed</Custom>
        <Custom Action="RemoveScheduledTaskInterval" Before="RemoveFiles">Installed</Custom>
    </InstallExecuteSequence>

    <CustomAction Id="CreateScheduledTaskLogon"
        Return="check"
        Impersonate="no"
        Execute="deferred"
        Directory="TARGETDIR"
        ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Create /RU SYSTEM /RP /NP /SC ONLOGON /TN &quot;mbackup-logon&quot; /TR &quot;[MBACKUP_PROGRAM_FILES]publish\mbackup.exe&quot; /DELAY 0015:00" />
    <CustomAction Id="RemoveScheduledTaskLogon"
        Return="check"
        Impersonate="no"
        Execute="deferred"
        Directory="TARGETDIR"
        ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Delete /TN &quot;mbackup-logon&quot; /F" />
    <CustomAction Id="CreateScheduledTaskInterval"
        Return="check"
        Impersonate="no"
        Execute="deferred"
        Directory="TARGETDIR"
        ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Create /RU SYSTEM /RP /NP /SC DAILY /TN &quot;mbackup-interval&quot; /TR &quot;[MBACKUP_PROGRAM_FILES]publish\mbackup.exe&quot; /ST 09:00 /DU 17:00 /RI 120 /K" />
    <CustomAction Id="RemoveScheduledTaskInterval"
        Return="check"
        Impersonate="no"
        Execute="deferred"
        Directory="TARGETDIR"
        ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Delete /TN &quot;mbackup-interval&quot; /F" />

    <Feature Id="MainApplication" Title="Main Application" Level="1">
    <Feature Id="MainApplication" Title="Main Application" Level="1">
      <ComponentGroupRef Id="MbackupHeatGenerated" />
      <ComponentGroupRef Id="MbackupHeatGenerated" />
      <ComponentGroupRef Id="RsyncHeatGenerated" />
      <ComponentGroupRef Id="RsyncHeatGenerated" />
+70 −2
Original line number Original line Diff line number Diff line
@@ -91,6 +91,8 @@ dotnet run -- -i
  https://www.firegiant.com/wix/tutorial/getting-started/
  https://www.firegiant.com/wix/tutorial/getting-started/


  Then you can follow the how-tos.
  Then you can follow the how-tos.
  How To Guides
  https://wixtoolset.org/documentation/manual/v3/howtos/


  How To: Implement a Major Upgrade In Your Installer
  How To: Implement a Major Upgrade In Your Installer
  https://wixtoolset.org/documentation/manual/v3/howtos/updates/major_upgrade.html
  https://wixtoolset.org/documentation/manual/v3/howtos/updates/major_upgrade.html
@@ -105,6 +107,9 @@ dotnet run -- -i
  https://docs.microsoft.com/en-us/windows/win32/msi/ice90
  https://docs.microsoft.com/en-us/windows/win32/msi/ice90
  https://docs.microsoft.com/en-us/windows/win32/msi/ice69
  https://docs.microsoft.com/en-us/windows/win32/msi/ice69


  CustomAction Element
  https://wixtoolset.org/documentation/manual/v3/xsd/wix/customaction.html

** 2019-11-13 install dir layout.
** 2019-11-13 install dir layout.
C:\Program Files\mbackup\rsync-w64\usr\bin\rsync.exe
C:\Program Files\mbackup\rsync-w64\usr\bin\rsync.exe
C:\Program Files\mbackup\rsync-w64\usr\bin\ssh.exe
C:\Program Files\mbackup\rsync-w64\usr\bin\ssh.exe
@@ -221,6 +226,9 @@ vscode should at least always indent using space for F#.


* current                                                             :entry:
* current                                                             :entry:
** 
** 
** 2019-11-16 how to sign my msi executable?
so it doesn't show publisher unknown.

** 2019-11-12 make code work in a specific dir. then create an installer.
** 2019-11-12 make code work in a specific dir. then create an installer.
- bundle dotnet core 3 with installer.
- bundle dotnet core 3 with installer.
- DONE install binary files to %programfiles%
- DONE install binary files to %programfiles%
@@ -229,9 +237,9 @@ vscode should at least always indent using space for F#.


  SCHTASKS /Create /?
  SCHTASKS /Create /?
  # run mbackup 15m after user logon.
  # run mbackup 15m after user logon.
  SCHTASKS /Create /NP /SC ONLOGON /TN mbackup-logon /TR "\"<path\to\mbackup.exe>\" \"args\"" /DELAY 15:00
  SCHTASKS /Create /NP /SC ONLOGON /TN mbackup-logon /TR "\"<path\to\mbackup.exe>\" \"args\"" /DELAY 0015:00
  # run mbackup at 10am and 4pm.
  # run mbackup at 10am and 4pm.
  SCHTASKS /Create /NP /SC DAILY /TN mbackup-morning /TR "\"<path\to\mbackup.exe>\" \"args\"" /ST 10:00 /ET 13:00 /K
  SCHTASKS /Create /NP /SC DAILY /TN mbackup-morning /TR "\"<path\to\mbackup.exe>\" \"args\"" /ST 10:00 /ET 14:00 /K
  SCHTASKS /Create /NP /SC DAILY /TN mbackup-afternoon /TR "\"<path\to\mbackup.exe>\" \"args\"" /ST 16:00 /ET 19:00 /K
  SCHTASKS /Create /NP /SC DAILY /TN mbackup-afternoon /TR "\"<path\to\mbackup.exe>\" \"args\"" /ST 16:00 /ET 19:00 /K


  # debug purpose, one time only
  # debug purpose, one time only
@@ -304,6 +312,66 @@ vscode should at least always indent using space for F#.
    logary/LICENSE.md at master · logary/logary · GitHub
    logary/LICENSE.md at master · logary/logary · GitHub
    https://github.com/logary/logary/blob/master/LICENSE.md
    https://github.com/logary/logary/blob/master/LICENSE.md
    this one is not free software.
    this one is not free software.
  - 2019-11-16 create scheduled task fail when installing.
    how to check the output of the command?
    msiexec /l*v log.txt /i mbackup-0.4.0.0.msi
    only log error
    msiexec /le loge.txt /i mbackup-0.4.0.0.msi

    it's mbackup.exe path problem.
    [INSTALLFOLDER] expands to empty string.

    [INSTALLFOLDER]\publish\mbackup.exe
    -->
    [MBACKUP_PROGRAM_FILES]publish\mbackup.exe
  - after this change, command runs fine in admin cmd.exe window.
    but when run in installer, still fail.
  - &quot;[SystemFolder]SCHTASKS.EXE&quot;
    -->
    SCHTASKS.EXE
    same error. not escaping issue.
  - error 1722 from simplest of .exe custom actions - Community
    https://community.flexera.com/t5/InstallShield-Forum/error-1722-from-simplest-of-exe-custom-actions/td-p/66380

    notepad.exe works in my case.
    when I exit notepad.exe, installer exit successfully.
    does it run as admin user? check.

    it's run as system user. not administrator or current user.
    it can't access desktop/documents etc.
    maybe that's the reason?

    » Using Windows Installer (WIX) to schedule a task as the system user RainbowInWater
    http://kamivaniea.com/?p=632

    SCHTASKS.EXE /Create /RU SYSTEM /RP /NP /SC ONLOGON /TN mbackup-logon /TR "C:\Program Files\mbackup\publish\mbackup.exe" /DELAY 0015:00

  - try add /RU SYSTEM /RP
    it works.

    TODO task will run as SYSTEM user though.
    how would home dir expand in SYSTEM user?
    I'd like task to run as currently logon user. for ONLOGON.

  - TODO why start menu shortcuts doesn't appear in win 10 guest?
    start menu folder is created. but only one exe there.
    txt file shortcuts are not added.

  - DAILY trigger, why repeat every 10min?

    #+BEGIN_QUOTE
    /RI   interval     Specifies the repetition interval in minutes. This is
                       not applicable for schedule types: MINUTE, HOURLY,
                       ONSTART, ONLOGON, ONIDLE, ONEVENT.
                       Valid range: 1 - 599940 minutes.
                       If either /ET or /DU is specified, then it defaults to
                       10 minutes.
    #+END_QUOTE
    just remove /ET? /K requires /ET.

    I can make use of /RI, run mbackup every 30min.
    TODO what happen if last run have not finished yet?
    does /RI interval count from last exit?
  - 
  - 


** 2019-11-12 how to test it? test it in a win 10 VM?
** 2019-11-12 how to test it? test it in a win 10 VM?