Reputation: 3
This is my code:
Dim exePath As String = Application.ExecutablePath()
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store", True)
key.DeleteValue(exePath)
But I don't know why the application doesn't delete that key.
Example: It finds the key but it doesn't delete that key
Upvotes: 0
Views: 2772
Reputation: 18320
That value is created automatically by the system when starting the application, meaning you cannot remove it while your app is running.
You can delete it after your app has closed if you want, but you must delete it from a separate application and it will be re-created again the next time you launch your app.
Starting a simple cmd
instance to do the deleting for you is enough:
Dim psi As New ProcessStartInfo("cmd.exe", "/C timeout /t 3 /nobreak > NUL & reg delete ""HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store"" /v """ & Application.ExecutablePath & """ /f")
psi.CreateNoWindow = True
psi.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(psi)
Upvotes: 0
Reputation: 5758
In order to delete the key,use the DeleteSubKey
method. An example would look like this:
My.computer.Registry.Currentuser.DeleteSubKey(keypath)
However, according to MSDN, exceptions may occur if
The name of the key is nothing or null
The user doesn't have required permission to delete/read/write the key
The key name exceeds 255 characters
The key is set to read-only
Upvotes: 2