@@ -39,42 +39,54 @@ function Invoke-WPFInstall {
3939 $user = $env: USERNAME
4040
4141 Get-LocalUser | Where-Object Enabled -eq $true | ForEach-Object {
42- try {
43- $myPasswordIsBlank = $PrincipalContext.ValidateCredentials ($user , $null )
44- } catch {
45- $form = New-Object System.Windows.Forms.Form
46- $form.Text = " Set password for $user "
47- $form.Size = New-Object System.Drawing.Size(500 , 200 )
42+ $validPassword = $false
43+ while (-not $validPassword ) {
44+ try {
45+ $myPasswordIsBlank = $PrincipalContext.ValidateCredentials ($user , $null )
46+ $validPassword = $true
47+ } catch {
48+ $form = New-Object System.Windows.Forms.Form
49+ $form.Text = " Set password for $user "
50+ $form.Size = New-Object System.Drawing.Size(500 , 200 )
4851
49- $label = New-Object System.Windows.Forms.Label
50- $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.
51- REMEMBER THE PASSWORD FOR THE FUTURE. YOU WILL NEED FOR STUFF AND TO LOGIN IF AUTOLOGIN ISN`T SET'
52- $label.Size = New-Object System.Drawing.Size(480 , 60 )
53- $label.Location = New-Object System.Drawing.Point(10 , 10 )
54- $form.Controls.Add ($label )
52+ $label = New-Object System.Windows.Forms.Label
53+ $label.Text = ' Admin mode install failed. Set a USER password for login and user-based installation.'
54+ $label.Size = New-Object System.Drawing.Size(480 , 60 )
55+ $label.Location = New-Object System.Drawing.Point(10 , 10 )
56+ $form.Controls.Add ($label )
5557
56- $passwordBox = New-Object System.Windows.Forms.TextBox
57- $passwordBox.Size = New-Object System.Drawing.Size(380 , 20 )
58- $passwordBox.UseSystemPasswordChar = $true
59- $passwordBox.Location = New-Object System.Drawing.Point(10 , 125 )
60- $form.Controls.Add ($passwordBox )
58+ $passwordBox = New-Object System.Windows.Forms.TextBox
59+ $passwordBox.Size = New-Object System.Drawing.Size(380 , 20 )
60+ $passwordBox.UseSystemPasswordChar = $true
61+ $passwordBox.Location = New-Object System.Drawing.Point(10 , 125 )
62+ $form.Controls.Add ($passwordBox )
6163
62- $button = New-Object System.Windows.Forms.Button
63- $button.Text = ' Submit'
64- $button.Size = New-Object System.Drawing.Size(75 , 23 )
65- $button.Location = New-Object System.Drawing.Point(400 , 125 )
66- $button.Add_Click ({
67- $password = $passwordBox.Text | ConvertTo-SecureString - AsPlainText - Force
68- if ($password ) {
69- Set-LocalUser - Name $user - Password $password
70- $Form.Close ()
71- } else {
72- [System.Windows.Forms.MessageBox ]::Show(' No password entered!' )
64+ $button = New-Object System.Windows.Forms.Button
65+ $button.Text = ' Submit'
66+ $button.Size = New-Object System.Drawing.Size(75 , 23 )
67+ $button.Location = New-Object System.Drawing.Point(400 , 125 )
68+ $button.Add_Click ({
69+ $password = $passwordBox.Text | ConvertTo-SecureString - AsPlainText - Force
70+ if ($password ) {
71+ try {
72+ Set-LocalUser - Name $user - Password $password
73+ $validPassword = $PrincipalContext.ValidateCredentials ($user , $passwordBox.Text )
74+ if ($validPassword ) {
75+ $form.Close ()
76+ } else {
77+ [System.Windows.Forms.MessageBox ]::Show(' Invalid password! Please try again.' )
78+ }
79+ } catch {
80+ [System.Windows.Forms.MessageBox ]::Show(' Error setting password!' )
81+ }
82+ } else {
83+ [System.Windows.Forms.MessageBox ]::Show(' No password entered!' )
84+ }
85+ })
86+ $form.Controls.Add ($button )
87+ $form.ShowDialog () | Out-Null
7388 }
74- })
75- $form.Controls.Add ($button )
76- $form.ShowDialog () | Out-Null
77- }
89+ }
7890 }
7991
8092 Show-WPFInstallAppBusy - text " Installing apps..."
0 commit comments