I'm looking for a simple script for a password-check in a Powershell GUI.
I have tried different types of codes but sometimes it can't read the textbox and sometimes it can't register the clicks.
So I have two buttons and a textbox.
- If I have the right password and press enter I want it to do something.
- If I have the wrong password I can try again.
But I have no idea how to do this with buttons in a GUI.
So I wonder I anyone has done something similar?
Heres what I have now about the "if" statment:
if ($Result = [System.Windows.Forms.DialogResult]::OK) {
$OKButton.Add_Click( { $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK })
$OKButton.Add_Enter( { $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK })
$CancelButton.Add_Click( { $CancelButton.Add_Click( { $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel }) })
if (([string]::IsNullOrEmpty($MaskedTextBox)) -or ([string]::IsNullOrEmpty($Pword))) {
write-host "Passwords can not be NULL or empty"
}
else {
if ($MaskedTextBox -cne $PWord) {
write-host "Fel"
}
else {
($MaskedTextBox -eq $PWord)
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\USBSTOR\" -Name "start" -Value 3
write-host "Rätt"
}
}
}