From ea618b2b6f23cc0ad2bb07b070e892c0f9a11238 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Mon, 5 Mar 2018 23:55:17 +0100
Subject: [PATCH] Register the tray app for auto-start on user login.

Fixes #30
---
 Updater/Update-Service.ps1 | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/Updater/Update-Service.ps1 b/Updater/Update-Service.ps1
index 7a6ec29..26c4c2a 100644
--- a/Updater/Update-Service.ps1
+++ b/Updater/Update-Service.ps1
@@ -66,6 +66,26 @@ function Stop-TrayApp() {
 }
 
 
+function Create-TrayAppStartupShortcut() {
+    $StartupDir = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
+    $ShortcutFile = "$($StartupDir)\AutoTxTray.lnk"
+    if (Test-Path -Type Leaf $ShortcutFile) {
+        Write-Verbose "Startup menu shortcut already existing."
+        Return
+    }
+    try {
+        $WshShell = New-Object -ComObject WScript.Shell
+        $Shortcut = $WshShell.CreateShortcut($ShortcutFile)
+        $Shortcut.TargetPath = "$($InstallationPath)\ATxTray.exe"
+        $Shortcut.Save()
+        Log-Debug "Created startup menu shortcut for tray app."
+    }
+    catch {
+        Log-Debug "Creating tray app shortcut failed: $($_.Exception.Message)"
+    }
+}
+
+
 function Exit-IfDirMissing([string]$DirName, [string]$Desc) {
     if (Test-Path -PathType Container $DirName) {
         Write-Verbose "Verified $($Desc) path: [$($DirName)]"
@@ -674,6 +694,8 @@ catch {
     Log-Error $UpdDetails
 }
 
+Create-TrayAppStartupShortcut
+
 
 Send-MailReport -Subject "$UpdSummary" -Body "$UpdDetails"
 
-- 
GitLab