Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Winget-AutoUpdate/Winget-Upgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ if ($true -eq $IsSystem) {
Start-Process `
-FilePath $ServiceUIexe `
-ArgumentList "-process:explorer.exe $env:windir\System32\conhost.exe --headless powershell.exe -NoProfile -ExecutionPolicy Bypass -File winget-upgrade.ps1" `
-WorkingDirectory $WorkingDir `
-Wait
-WorkingDirectory $WorkingDir
Wait-Process "ServiceUI" -ErrorAction SilentlyContinue
Exit 0
}
else {
Expand Down
13 changes: 13 additions & 0 deletions Sources/Winget-AutoUpdate/mods/_AppID-template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ $AllVersions = $False
# Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1*","lnk2"
$Lnk = @("")

# Create Start Menu Shortcuts, without .lnk, multiple: "lnk1","lnk2". Example:
# - Supports subdirectories in shortcut names (e.g., "Folder\ShortcutName")
# - $Shortcuts and $ShortcutsTargets arrays must match in length and order
# - Shortcuts are only created if the target file exists
# Example:
# $Shortcuts = @("dnGrep\dnGrep")
# $ShortcutsTargets = @("${env:ProgramFiles}\dnGrep\dnGrep.exe")
$Shortcuts = @("")
$ShortcutsTargets = @("") # Must match the order of $Shortcuts

# Registry _value_ (DWord/String) to add in existing registry Key (Key created if not existing). Example:
# $AddKey = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"
# $AddValue = "WAU_BypassListForUsers"
Expand Down Expand Up @@ -129,6 +139,9 @@ if ($AppUninst) {
if ($Lnk) {
Remove-ModsLnk $Lnk
}
if ($Shortcuts -and $Shortcuts[0]) {
Add-ProgramsShortcuts $Shortcuts $ShortcutsTargets
}
if ($AddKey -and $AddValue -and $AddTypeData -and $AddType) {
Add-ModsReg $AddKey $AddValue $AddTypeData $AddType
}
Expand Down
51 changes: 51 additions & 0 deletions Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,57 @@ function Remove-ModsLnk ($Lnk) {
Return $removedCount
}

function Add-ProgramsShortcuts ($Shortcuts, $ShortcutsTargets) {
$programsPath = "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs"
$createdCount = 0

# Validate arrays match in length and are not just empty placeholders
if ($Shortcuts.Count -ne $ShortcutsTargets.Count -or ($Shortcuts.Count -eq 1 -and [string]::IsNullOrEmpty($Shortcuts[0]))) {
Return $createdCount
}

# Create WScript.Shell COM object
$WshShell = New-Object -ComObject WScript.Shell -ErrorAction SilentlyContinue
if (!$WshShell) {
Return $createdCount
}

# Iterate through shortcuts
for ($i = 0; $i -lt $Shortcuts.Count; $i++) {
$shortcutName = $Shortcuts[$i]
$targetPath = $ShortcutsTargets[$i]

# Skip empty entries
if ([string]::IsNullOrEmpty($shortcutName) -or [string]::IsNullOrEmpty($targetPath)) {
continue
}

# Construct full shortcut path
$shortcutPath = Join-Path $programsPath "$shortcutName.lnk"

# Create parent directory if it doesn't exist
$shortcutDir = Split-Path $shortcutPath -Parent
if (!(Test-Path $shortcutDir)) {
New-Item -Path $shortcutDir -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null
}

# Verify target exists
if (Test-Path $targetPath) {
# Create shortcut
$shortcut = $WshShell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $targetPath
$parentPath = Split-Path $targetPath -Parent
if (![string]::IsNullOrEmpty($parentPath)) {
$shortcut.WorkingDirectory = $parentPath
}
$shortcut.Save()
$createdCount++
}
}

Return $createdCount
}

function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) {
if ($AddKey -like "HKEY_LOCAL_MACHINE*") {
$AddKey = $AddKey.replace("HKEY_LOCAL_MACHINE", "HKLM:")
Expand Down
Loading