0
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(500,300)
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen

$label = New-Object System.Windows.Forms.Label
$label.Text = "Click the button to view the ProfileList registry in regedit"
$label.Size = New-Object System.Drawing.Size(300,30)
$label.Location = New-Object System.Drawing.Point(100,50)

$display_button = New-Object System.Windows.Forms.Button
$display_button.Text = "Display ProfileList"
$display_button.Size = New-Object System.Drawing.Size(150,30)
$display_button.Location = New-Object System.Drawing.Point(175,100)

$display_button.Add_Click({
regedit "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
})

$form.Controls.Add($label)
$form.Controls.Add($display_button)
$form.ShowDialog()

Upon running the script I receive the following error: "Error opening the file"

I am not sure if the path is correct, can someone point out what I'm doing wrong?

2
  • 3
    A parameter to regedit tells the program to open what it expects is a file in .reg format and import the data into the registry. It does not open the registry with that key in view. Commented Feb 3, 2023 at 12:25
  • 1
    Try RegJump, by Mark Russinovich, that does just what you want. It'll launch regedit and move it to the key you want from the command line. Commented Feb 3, 2023 at 12:49

1 Answer 1

1

Before opening regedit.exe, perform the following:

Set-ItemProperty 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit' 'LastKey' 'Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'

or

$splat = @{
    'Path'   = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit'
    'Name'   = 'LastKey'
    'Value'  = 'Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
}
Set-ItemProperty @splat

and edit your button click actdion to simply:

$display_button.Add_Click({
    regedit
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.