写入注册表时发生异常 [英] exception while write to registry

查看:162
本文介绍了写入注册表时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试哟,让我的应用程序在Windows启动时自动启动.它在Windows XP上可以正常运行,但在Windows 7 Professional 64B,Window Vista Ultimate 32B和Window Vista Business 32B上出现错误试图执行未经授权的操作"

我正在使用以下代码:

Hi,

I am try yo make my application autostart when windows start. It works fine on windows XP but gives me error "Attempt to perform an unauthorized operation" on Windows 7 Professional 64B, Window Vista Ultimate 32B and Window Vista Business 32B

I am using below code:

Try
      Dim regKey As RegistryKey
      regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)

      If MyAppsCheckBox.Checked = true Then
        regKey.SetValue("MyApp", Application.ExecutablePath.ToString())
      Else
        regKey.DeleteValue("MyApp", True)
      End If
      regKey.Close()
    Catch ex As Exception
      msgbox(ex.Message)
    End Try



我找不到上述问题的解决方案.
请帮助



I am unable to find the solution for above problem.
Please help

推荐答案

Windows 7使用用户帐户控制,除非您以管理员身份运行该程序,否则将不允许您写入注册表.
您还有另一个选择是使用高架"清单文件-阅读有关此方法的更多信息
Windows 7 uses User Account Control and will not allow you to write to the registry unless you run the program as an administrator.

The other option you have is to use an ''Elevated'' manifest file - read more about this approach here[^].


这篇关于写入注册表时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆