Hello to all,
i am a beginner in powershell, maybe you can help me.
This script opens a window where you can enter a licensekey,
and this key will be written in a certain Reghive. ("HKLM:\SOFTWARE\CompanyName")
Now i try to add a question, after you added the licensekey.
A question should appear below the entered licensekey, if this key is correct, "Is this Key correct?"
if you press "no" it should go back to the first window where you can re-enter the key
if you press "yes" the key will be written and the program closes
if the RegKey is already present ("HKLM:\SOFTWARE\CompanyName")
there should be an additional question
"Should the licensekey be overwritten?"
press "yes" and the key will be overwritten and the program closes, if "no" the program closes because the key is already there.
i hope you can help me
greetings
Script:
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq"Enter")
{$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq"Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(108,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)
# $CancelButton = New-Object System.Windows.Forms.Button
# $CancelButton.Location = New-Object System.Drawing.Size(150,120)
# $CancelButton.Size = New-Object System.Drawing.Size(75,23)
# $CancelButton.Text = "Cancel"
# $CancelButton.Add_Click({$objForm.Close()})
# $objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please enter the licence key in the space below:"
$objForm.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$x
New-Item -Path"HKLM:\SOFTWARE\CompanyName"
$RegistryPath=”HKLM:SOFTWARE\CompanyName\"
$Name=”Licensekey”
$Value=”$x”
NEW-ITEMPROPERTY $RegistryPath -Name $Name -Value $Value