最近,我创建了一个程序,可以使用访问Registry的Visual Studio 2013添加可执行文件来启动。 问题是当单击包含方法/操作错误的命令时显示:
mscorlib.dll中出现未处理的“System.Security.SecurityException”类型异常
其他信息:不允许请求的注册表访问。
里面的代码是:
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim regKey As Microsoft.Win32.RegistryKey
Dim keyName As String = txtKeyName.Text
Dim keyValue As String = txtPath.Text
regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
If (regKey.GetValue(keyName)) = Nothing Then
MsgBox("No value found")
regKey.SetValue(keyName, keyValue, Microsoft.Win32.RegistryValueKind.String)
MsgBox("Key " & keyName & " Has been Created")
Else
MsgBox("This Program already exists", vbInformation, "Information")
End If
答案 0 :(得分:0)
为了写入注册表的某些部分,您必须在Windows中具有提升的权限。要强制您的应用程序要求提升权限,您可以在项目属性>>中设置此权限。申请>>查看窗口设置。