Reg write & delete

Johnson

Well-known member
Joined
Mar 6, 2009
Messages
158
Programming Experience
Beginner
if this writes this key

VB.NET:
        Private Sub chkStartup_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkStartup.CheckedChanged
            If chkStartup.Checked = True Then

                Dim AppPath As String = Application.ExecutablePath
                Dim CU As Microsoft.Win32.RegistryKey = _
        Registry.CurrentUser.CreateSubKey _
        ("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")

                With CU
                    .OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
                    .SetValue("WebRequest", AppPath)
                End With
            Else

            End If

        End Sub

what would delete that? been trying all sorts
 
Any reason DeleteSubKey does not work for you?
...On second thought, I see now that you intend to delete a value, not a key. So open the Run key as writeable and use the DeleteValue to delete the 'WebRequest' value.

The Run key should be present already by the way, it's a system key, so no need to create it as far as I know. If not you can always trap the value returned to see it it's Nothing, and only then call CreateSubKey.
 
Dam you posted to quick lol.

I just recoded it to

VB.NET:
        Private Sub chkStartup_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkStartup.CheckedChanged
            If chkStartup.Checked = True Then
                Dim AppPath As String = Application.ExecutablePath
                My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", _
        "WebRequest", AppPath)
            Else
                Dim skey As String = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\WebRequest"
                My.Computer.Registry.CurrentUser.DeleteSubKey(sKey)

            End If
        End Sub

which seems so much easier,

But the delete says subkey does not exists, which is what us aid about its an actual value?

im not sure how i delete the value
 
Ok, i just tryed this

VB.NET:
                My.Computer.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
                My.Computer.Registry.CurrentUser.DeleteValue("WebRequest")
                My.Computer.Registry.CurrentUser.Close()

and it says no value exists with that name. It clearly does
 
The Run key has a WebRequest value. You have to use the OpenSubKey function to open the Run key, and with this key call DeleteValue.
VB.NET:
Dim key = My.Computer.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
key.DeleteValue("WebRequest")
key.Close()
 
Thank you. Just above your post was my new code simular.

i can see now where it was wrong. even though i opened the run subkey when i called the delete it was just trying to find currentuser webrequest
 
What you should do is to open the registry with the Regedit.exe Window app and look around, it will help you understand its tree structure. In the left pane you will see the root system keys with all the subkeys in the tree, in the right pane the name-value pairs of the selected key. Operating it with the Registry classes is really no different.
 
will do, thanks

Just one more thing, My application opens with %1 which allows my appliction to upload the selected image but what is %1????

i have also seen %2 %3 etc but cant find no info on the net.

%1 returns full exe path and then file path
 
Back
Top