Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceUI added to handle some apps #437

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions .github/workflows/WAU-AutoCreatePreVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ jobs:

- name: Build project
run: |
# Get MDT from Microsoft
wget https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi
# Extract MSI
7z x MicrosoftDeploymentToolkit_x64.msi
# Copy ServiceUI.exe to Winget-AutoUpdate folder
mv Modena_File206 Winget-AutoUpdate/ServiceUI.exe
# Zip WAU
zip -r WAU.zip Winget-AutoUpdate
zip WAU.zip Winget-AutoUpdate-Install.ps1
zip WAU.zip excluded_apps.txt
zip WAU.zip install.bat
zip WAU.zip uninstall.bat
# Zip ADMX
cd Policies
zip -r ../WAU_ADMX.zip *
cd ..
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/WAU-CreateNewVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ jobs:

- name: Build project
run: |
# Get MDT from Microsoft
wget https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi
# Extract MSI
7z x MicrosoftDeploymentToolkit_x64.msi
# Copy ServiceUI.exe to Winget-AutoUpdate folder
mv Modena_File206 Winget-AutoUpdate/ServiceUI.exe
# Zip WAU
zip -r WAU.zip Winget-AutoUpdate
zip WAU.zip Winget-AutoUpdate-Install.ps1
zip WAU.zip excluded_apps.txt
zip WAU.zip install.bat
zip WAU.zip uninstall.bat
# Zip ADMX
cd Policies
zip -r ../WAU_ADMX.zip *
cd ..
Expand Down
30 changes: 25 additions & 5 deletions Winget-AutoUpdate/Winget-Upgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,31 @@ $Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsS

#Log initialisation
$LogFile = "$WorkingDir\logs\updates.log"
Write-ToLog -LogMsg "CHECK FOR APP UPDATES" -IsHeader

if ($IsSystem) {
#Check if any connected user when running as system
$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
#Check if ServiceUI exists
$ServiceUI = Test-Path "$WorkingDir\ServiceUI.exe"
If ($explorerprocesses.Count -gt 0 -and $ServiceUI) {
#User connected, Check for current session ID (O = system)
$SessionID = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
if ($SessionID -eq 0) {
#Rerun WAU in system context with ServiceUI
& $WorkingDir\ServiceUI.exe -process:explorer.exe $env:windir\System32\wscript.exe \`"$WorkingDir\Invisible.vbs\`" \`"powershell.exe -NoProfile -ExecutionPolicy Bypass -File \`"\`"$WorkingDir\winget-upgrade.ps1\`"\`"\`"
Exit 0
}
else {
Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context with ServiceUI)" -IsHeader
}
}
else {
Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context)" -IsHeader
}
}
else {
Write-ToLog -LogMsg "CHECK FOR APP UPDATES (User context)" -IsHeader
}

#Get settings and Domain/Local Policies (GPO) if activated.
$Script:WAUConfig = Get-WAUConfig
Expand All @@ -27,7 +51,6 @@ if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {

#Log running context and more...
if ($IsSystem) {
Write-ToLog "Running in System context"

# Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files.
$MaxLogFiles = $WAUConfig.WAU_MaxLogFiles
Expand Down Expand Up @@ -61,9 +84,6 @@ if ($IsSystem) {
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json"
Add-ScopeMachine $SettingsPath
}
else {
Write-ToLog "Running in User context"
}

#Get Notif Locale function
$LocaleDisplayName = Get-NotifLocale
Expand Down
2 changes: 1 addition & 1 deletion Winget-AutoUpdate/functions/Confirm-Installation.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Function Confirm-Installation ($AppName, $AppVer){

#Set json export file
$JsonFile = "$WorkingDir\Config\InstalledApps.json"
$JsonFile = "$WorkingDir\InstalledApps.json"

#Get installed apps and version in json file
& $Winget export -s winget -o $JsonFile --include-versions | Out-Null
Expand Down
1 change: 1 addition & 0 deletions Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function Invoke-PostUpdateActions {
Write-ToLog "-> Policies task created."
}


### End of post update actions ###

#Reset WAU_UpdatePostActions Value
Expand Down
2 changes: 1 addition & 1 deletion Winget-AutoUpdate/functions/Write-ToLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Write-ToLog {

#If header requested
if ($IsHeader) {
$Log = " `n##################################################`n# $LogMsg - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"
$Log = " `n########################################################`n# $LogMsg - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n########################################################"
}
else {
$Log = "$(Get-Date -UFormat "%T") - $LogMsg"
Expand Down