diff --git a/functions/private/Install-WinUtilProgramWinget.ps1 b/functions/private/Install-WinUtilProgramWinget.ps1 index 994d10b7..97180691 100644 --- a/functions/private/Install-WinUtilProgramWinget.ps1 +++ b/functions/private/Install-WinUtilProgramWinget.ps1 @@ -97,9 +97,9 @@ Function Install-WinUtilProgramWinget { return $true } - $userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $($Program) installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User credential Prompt", [System.Windows.MessageBoxButton]::YesNo) - if ($userChoice -eq 'Yes') { - $getcreds = Get-Credential + $userAcknowledgment = [System.Windows.MessageBox]::Show("You need to input your password to install $($Program) with specific user credentials.", "User credential Prompt", [System.Windows.MessageBoxButton]::Ok) + if ($userAcknowledgment -eq 'Ok') { + $getcreds = Get-Credential $env:USERNAME $status = Invoke-Winget -wingetId $Program -credential $getcreds if ($status -eq 0) { Write-Host "$($Program) installed successfully with User prompt." diff --git a/functions/public/Invoke-WPFInstall.ps1 b/functions/public/Invoke-WPFInstall.ps1 index 2aeb8ca5..cb0100ef 100644 --- a/functions/public/Invoke-WPFInstall.ps1 +++ b/functions/public/Invoke-WPFInstall.ps1 @@ -4,10 +4,8 @@ function Invoke-WPFInstall { [PSObject[]]$PackagesToInstall = $($sync.selectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_ }) ) <# - .SYNOPSIS Installs the selected programs using winget, if one or more of the selected programs are already installed on the system, winget will try and perform an upgrade if there's a newer version to install. - #> if($sync.ProcessRunning) { @@ -34,12 +32,55 @@ function Invoke-WPFInstall { try { $sync.ProcessRunning = $true - Show-WPFInstallAppBusy -text "Installing apps..." + if($packagesWinget.Count -gt 0 -and $packagesWinget -ne "0") { + Add-Type -AssemblyName System.DirectoryServices.AccountManagement + Add-Type -assembly System.Windows.Forms + $PrincipalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('Machine') + $user = $env:USERNAME - if($packagesWinget.Count -gt 0) { + Get-LocalUser | Where-Object Enabled -eq $true | ForEach-Object { + try { + $myPasswordIsBlank = $PrincipalContext.ValidateCredentials($user, $null) + } catch { + $form = New-Object System.Windows.Forms.Form + $form.Text = "Set password for $user" + $form.Size = New-Object System.Drawing.Size(500, 200) + + $label = New-Object System.Windows.Forms.Label + $label.Text = 'Maybe a program needs to be installed in "usermode" and you have no password set, you need to set it here. After putting a password into the text box a page asking for your password might open (not right after). If you keep the text box empty, nothing will happen. + REMEMBER THE PASSWORD FOR THE FUTURE. YOU WILL NEED FOR STUFF AND TO LOGIN IF AUTOLOGIN ISN`T SET' + $label.Size = New-Object System.Drawing.Size(480, 60) + $label.Location = New-Object System.Drawing.Point(10, 10) + $form.Controls.Add($label) + + $passwordBox = New-Object System.Windows.Forms.TextBox + $passwordBox.Size = New-Object System.Drawing.Size(380, 20) + $passwordBox.UseSystemPasswordChar = $true + $passwordBox.Location = New-Object System.Drawing.Point(10, 125) + $form.Controls.Add($passwordBox) + + $button = New-Object System.Windows.Forms.Button + $button.Text = 'Submit' + $button.Size = New-Object System.Drawing.Size(75, 23) + $button.Location = New-Object System.Drawing.Point(400, 125) + $button.Add_Click({ + $password = $passwordBox.Text | ConvertTo-SecureString -AsPlainText -Force + if ($password) { + Set-LocalUser -Name $user -Password $password + $password.Close() + $Form.Close() + } else { + [System.Windows.Forms.MessageBox]::Show('No password entered!') + } + }) + $form.Controls.Add($button) + $form.ShowDialog() | Out-Null + } + } + + Show-WPFInstallAppBusy -text "Installing apps..." Install-WinUtilWinget Install-WinUtilProgramWinget -Action Install -Programs $packagesWinget - } if($packagesChoco.Count -gt 0) { Install-WinUtilChoco