mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-12-17 17:55:28 +00:00
Fix: retry password prompt on failure to prevent script halting (#3581)
* Fix: retry password prompt on failure to prevent script halting * Update Invoke-WPFInstall.ps1 * format fix
This commit is contained in:
parent
af7030d536
commit
7db0b8a857
@ -39,16 +39,18 @@ function Invoke-WPFInstall {
|
|||||||
$user = $env:USERNAME
|
$user = $env:USERNAME
|
||||||
|
|
||||||
Get-LocalUser | Where-Object Enabled -eq $true | ForEach-Object {
|
Get-LocalUser | Where-Object Enabled -eq $true | ForEach-Object {
|
||||||
|
$validPassword = $false
|
||||||
|
while (-not $validPassword) {
|
||||||
try {
|
try {
|
||||||
$myPasswordIsBlank = $PrincipalContext.ValidateCredentials($user, $null)
|
$myPasswordIsBlank = $PrincipalContext.ValidateCredentials($user, $null)
|
||||||
|
$validPassword = $true
|
||||||
} catch {
|
} catch {
|
||||||
$form = New-Object System.Windows.Forms.Form
|
$form = New-Object System.Windows.Forms.Form
|
||||||
$form.Text = "Set password for $user"
|
$form.Text = "Set password for $user"
|
||||||
$form.Size = New-Object System.Drawing.Size(500, 200)
|
$form.Size = New-Object System.Drawing.Size(500, 200)
|
||||||
|
|
||||||
$label = New-Object System.Windows.Forms.Label
|
$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.
|
$label.Text = 'Admin mode install failed. Set a USER password for login and user-based installation.'
|
||||||
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.Size = New-Object System.Drawing.Size(480, 60)
|
||||||
$label.Location = New-Object System.Drawing.Point(10, 10)
|
$label.Location = New-Object System.Drawing.Point(10, 10)
|
||||||
$form.Controls.Add($label)
|
$form.Controls.Add($label)
|
||||||
@ -66,8 +68,17 @@ function Invoke-WPFInstall {
|
|||||||
$button.Add_Click({
|
$button.Add_Click({
|
||||||
$password = $passwordBox.Text | ConvertTo-SecureString -AsPlainText -Force
|
$password = $passwordBox.Text | ConvertTo-SecureString -AsPlainText -Force
|
||||||
if ($password) {
|
if ($password) {
|
||||||
|
try {
|
||||||
Set-LocalUser -Name $user -Password $password
|
Set-LocalUser -Name $user -Password $password
|
||||||
$Form.Close()
|
$validPassword = $PrincipalContext.ValidateCredentials($user, $passwordBox.Text)
|
||||||
|
if ($validPassword) {
|
||||||
|
$form.Close()
|
||||||
|
} else {
|
||||||
|
[System.Windows.Forms.MessageBox]::Show('Invalid password! Please try again.')
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
[System.Windows.Forms.MessageBox]::Show('Error setting password!')
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
[System.Windows.Forms.MessageBox]::Show('No password entered!')
|
[System.Windows.Forms.MessageBox]::Show('No password entered!')
|
||||||
}
|
}
|
||||||
@ -76,6 +87,7 @@ function Invoke-WPFInstall {
|
|||||||
$form.ShowDialog() | Out-Null
|
$form.ShowDialog() | Out-Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Show-WPFInstallAppBusy -text "Installing apps..."
|
Show-WPFInstallAppBusy -text "Installing apps..."
|
||||||
Install-WinUtilWinget
|
Install-WinUtilWinget
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user