如何删除注册表项?
How do I delete a registry key?
这是我的代码:
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)
但我不知道为什么应用程序不删除该密钥。
示例:找到密钥但未删除该密钥
要删除密钥,请使用DeleteSubKey
方法。示例如下所示:
My.computer.Registry.Currentuser.DeleteSubKey(keypath)
但是,according to MSDN,如果
,可能会出现异常
密钥名称为空或为空
用户没有delete/read/write密钥所需的权限
键名超过255个字符
密钥设置为只读
该值是系统在启动应用程序时自动创建的,这意味着当您的应用处于 运行[=22 时,您无法删除它 =].
如果需要,您可以在应用关闭后将其删除,但您必须从单独的应用程序中删除它并且下次启动时它将重新创建你的应用程序。
启动一个简单的 cmd
实例来为您执行删除操作就足够了:
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)
这是我的代码:
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)
但我不知道为什么应用程序不删除该密钥。
示例:找到密钥但未删除该密钥
要删除密钥,请使用DeleteSubKey
方法。示例如下所示:
My.computer.Registry.Currentuser.DeleteSubKey(keypath)
但是,according to MSDN,如果
,可能会出现异常密钥名称为空或为空
用户没有delete/read/write密钥所需的权限
键名超过255个字符
密钥设置为只读
该值是系统在启动应用程序时自动创建的,这意味着当您的应用处于 运行[=22 时,您无法删除它 =].
如果需要,您可以在应用关闭后将其删除,但您必须从单独的应用程序中删除它并且下次启动时它将重新创建你的应用程序。
启动一个简单的 cmd
实例来为您执行删除操作就足够了:
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)