I am able to give a prompt to the user using powershell script but the issue is that the user is able to ignore it. What I mean is the user is able to open other programs and file even when the prompt is there. I want that when the user is prompted he should not be able to open any other app or file until he reacts to the prompt.
`Add-Type -AssemblyName System.Windows.Forms
$result = [System.Windows.Forms.MessageBox]::Show(
"Do you want to change the BIOS password?",
"BIOS Password Change",
[System.Windows.Forms.MessageBoxButtons]::OKCancel,
[System.Windows.Forms.MessageBoxIcon]::Question
)
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Change BIOS Password"
$form.Size = New-Object System.Drawing.Size(320,220)
$form.StartPosition = "CenterScreen"
$labelOld = New-Object System.Windows.Forms.Label
$labelOld.Location = New-Object System.Drawing.Point(10,20)
$labelOld.Size = New-Object System.Drawing.Size(280,20)
$labelOld.Text = "Enter old BIOS password:"
$form.Controls.Add($labelOld)
$textboxOld = New-Object System.Windows.Forms.TextBox
$textboxOld.Location = New-Object System.Drawing.Point(10,40)
$textboxOld.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textboxOld)
$labelNew = New-Object System.Windows.Forms.Label
$labelNew.Location = New-Object System.Drawing.Point(10,70)
$labelNew.Size = New-Object System.Drawing.Size(280,20)
$labelNew.Text = "Enter new BIOS password:"
$form.Controls.Add($labelNew)
$textboxNew = New-Object System.Windows.Forms.TextBox
$textboxNew.Location = New-Object System.Drawing.Point(10,90)
$textboxNew.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textboxNew)
$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Point(75,130)
$button.Size = New-Object System.Drawing.Size(75,23)
$button.Text = "OK"
$button.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.Controls.Add($button)
$form.Add_Shown({
$textboxOld.Select()
})
$form.AcceptButton = $button
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$oldPassword = $textboxOld.Text
$newPassword = $textboxNew.Text
(gwmi -Class Lenovo_SetBiosPassword -Namespace rootwmi).SetBiosPassword("pap,$oldPassword,$newPassword,ascii,us")
[System.Windows.Forms.MessageBox]::Show(
"Restart your device to see the changes",
"Operation Cancelled",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Exclamation
)
} else {
[System.Windows.Forms.MessageBox]::Show(
"Password change cancelled.",
"Operation Cancelled",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Exclamation
)
}
} else {
[System.Windows.Forms.MessageBox]::Show(
"Password change cancelled.",
"Operation Cancelled",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Exclamation
)
}`
This is the powershell script I used to give a prompt to the user to change the bios password.But the user is able to ignore this prompt. He should react to this prompt before accessing any other file.
user26675830 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.