Witam,
piszę program w Visual Basic’u, który ma utworzyć w HKEY_LOCAL_MACHINE\SOFTWARE podklucz Mój Edytor.
Oto fragment kodu:
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Dim klucz As RegistryKey
Dim sciezka As String
Dim wartosc As Integer
sciezka = "SOFTWARE\Mój Edytor"
klucz = Registry.LocalMachine.OpenSubKey(sciezka, True)
klucz = Registry.LocalMachine.CreateSubKey(sciezka, True)
klucz.SetValue("firstopen", 0)
wartosc = CType(klucz.GetValue("firstopen"), Integer)
Kompilator nie zgłasza błędów do momentu włączenia aplikacji.
Wtedy pojawia się taki błąd:
System.ArgumentException was unhandled
HResult=-2147024809
Message=Określona wartość RegistryKeyPermissionCheck jest nieprawidłowa.
Nazwa parametru: mode
ParamName=mode
Source=mscorlib
StackTrace:
w System.ThrowHelper.ThrowArgumentException(ExceptionResource resource, ExceptionArgument argument)
w Microsoft.Win32.RegistryKey.CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, Object registrySecurityObj, RegistryOptions registryOptions)
w Microsoft.Win32.RegistryKey.CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck)
w Windows7RegistryEditor.My.MyApplication.MyApplication_Startup(Object sender, EventArgs e) w C:\Users\Gosia\documents\visual studio 2010\Projects\Windows7RegistryEditor\Windows7RegistryEditor\ApplicationEvents.vb:wiersz 23
w Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnStartup(StartupEventArgs eventArgs)
w Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
w Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
w Windows7RegistryEditor.My.MyApplication.Main(String[] Args) w 17d14f5c-a337-4978-8281-53493378c1071.vb:wiersz 81
w System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
w System.Threading.ThreadHelper.ThreadStart_Context(Object state)
w System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
w System.Threading.ThreadHelper.ThreadStart()
InnerException:
System Operacyjny: Windows 7 Home Premium x64
IDE: Microsoft Visual Basic 2010 Express
Czy ktoś wie jak to naprawić?
Pozdrawiam,
blondkarol