2016-06-04 2 views
0

저는 HKLM에서 키를 추가하고 값을 변경하는 데 어려움을 겪고 있습니다. 나는 다음과 같은 사용하여 문제없이 HKCU에 키와 설정 값을 추가 할 수 있습니다 내가 오류 " 'System.IO.IOException'형식의 처리되지 않은 예외가 발생 HKLM를 사용하여 비슷한 뭔가를 시도하는 경우에, 그러나HKEY_LOCAL_MACHINE에서 레지스트리 키를 추가/변경하는 방법

My.Computer.Registry.CurrentUser.CreateSubKey("TestKey") 
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\TestKey", "MyTestKeyValue", "This is a test value.") 

발생 나는이 응용 프로그램이 레지스트리에 읽기/쓰기 할 수있는 올바른 권한을 가지고 있지에 문제가 이해 것과

My.Computer.Registry.LocalMachine.CreateSubKey("TestKey") 
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\TestKey", "MyTestKeyValue", "This is a test value.") 

"mscorlib.dll에있다.

내가 거기에 다음과 같은 예를 볼 수 있지만 내 컴퓨터에서 작업을 얻을 수 없습니다 생각했습니다

:

Dim autoshell = My.Computer.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\Winlogon", True) 
'' Set the value to 0 
autoshell.SetValue("autorestartshell", 0) 
autoshell.Close() 

마지막으로, 나는이 매우 유망한 유튜브 튜토리얼에 나와있는 어떤 (https://www.youtube.com/watch?v=rrt9ti6bYi4)를 시도했습니다 하지만 다시 운이 :

Module RegistryFunctions 
    Public Sub Read_Registry() 
     Try 

      Dim pregkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\ScopeCreep\VideoTrac­ker", True) 
      Dim pRegKey_User = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\ScopeCreep\VideoTrack­er", True) 

      If Not (pRegKey_User Is Nothing) Then 
       frmLogin.tbUser.Text = pRegKey_User.GetValue("User") 
       frmLogin.tbDatabase.Text = pRegKey_User.GetValue("Database") 
      End If 

      If Not (pregkey Is Nothing) Then 
       frmLogin.tbServer.Text = pregkey.GetValue("Server") 
       frmLogin.cbEnabled.Checked = pregkey.GetValue("Enabled", False) 
      End If 

     Catch ex As Exception 
      MsgBox("Error in function Read_Registry: " & ex.Message) 
     End Try 
    End Sub 

    Public Sub Write_Registry() 

     Try 
      Dim Newkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\ScopeCreep\VideoTrac­ker", True) 
      If Newkey Is Nothing Then Newkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\ScopeCreep\VideoTr­acker") 

      Newkey.SetValue("Server", frmLogin.tbServer.Text) 
      Newkey.SetValue("Enabled", frmLogin.cbEnabled.Checked) 

      Newkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\ScopeCreep\VideoTrack­er", True) 
      If Newkey Is Nothing Then Newkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\ScopeCreep\VideoTra­cker") 

      Newkey.SetValue("User", frmLogin.tbUser.Text) 
      Newkey.SetValue("Database", frmLogin.tbDatabase.Text) 

     Catch ex As Exception 
      MsgBox("Error in Write Registry: " & ex.Message) 

     End Try 
    End Sub 
End Module 

여기서 문제, 내가 모듈의 코드 폼에있는 단추를 연결하는 방법을 정말 잘 모르겠어요 것이 없다. 나는 다음을 시도했다. (나는 무엇을해야할지 모르므로) 작동하지 않았다.

Private Sub btnRead_Click(sender As Object, e As EventArgs) Handles btnRead.Click 
    RegistryFunctions.Read_Registry() 
End Sub 

Private Sub btnWrite_Click(sender As Object, e As EventArgs) Handles btnWrite.Click 
    RegistryFunctions.Write_Registry() 
End Sub 

사람이 내가 한 것을 멍청한 짓을 수정하거나 내가이 작업을 완료 할 수있는 방법에 대한 정보를 제공 할 수있는 경우 은 내가 대단히 감사하겠습니다!

미리 감사드립니다.

+1

을 (http://stackoverflow.com/q/268424/ 1070452) – Plutonix

+0

새 응용 프로그램에 레지스트리를 사용해서는 안되는 데 동의하지만 실제로이 경우에는 적용되지 않습니다 (미안하지만 언급하지 않았습니다). 불행하게도 Windows 98 또는 2000을 실행하는 시스템 용으로 만들어진 레거시 응용 프로그램을 사용하고 있습니다. 변경해야 할 레지스트리 키는 HKLM에 있습니다. 필자는 기본적으로 배치 파일, PowerShell 스크립트 또는 수동 편집을 실행하는 대신 GUI를 사용하여 레지스트리를 변경하는 방법을 사용자에게 제공하려고합니다. 또한 이것은 응용 프로그램의 일부일뿐입니다. .reg 파일을 가져올 수 있다면 수정으로 받아 들일 수도 있습니다. – NoobieMcNooberson

+0

마지막 코멘트를 게시하는 동안 가져 오기 옵션을 사용하면 생각보다 쉽다고 느낄 수 있습니다. 다음 줄을 사용하여 .reg 파일을 가져올 수 있습니다. 관리자 권한에 대한 필요성을 제외하고 자동으로 수행하는 방법을 알아야합니다. Process.Start (My.Computer.FileSystem .CurrentDirectory & "\ test.reg") – NoobieMcNooberson

답변

1

.reg 파일을 가져 오는 방식을 취함으로써 HKLM에서 레지스트리 키를 성공적으로 변경할 수있었습니다. 나는이 방법을 쉽게 추가 할 수도있다. 끝내야 할 조정이 아직 있습니다 만, 이것이 트릭입니다!

내 보트에 누가 있었는지 알 수 있기를 바랍니다.

자세한 내용은, 내가 여기에 대답 위치 : [? - 왜 - Windows 레지스트리에 저장 한해야 데이터] http://www.vbforums.com/showthread.php?610140-Silently-import-reg-file

Private Sub btnRegKeys_Click(sender As Object, e As EventArgs) Handles btnRegKeys.Click 

    ' Dimensioning variables for the 64 bit keys, 32 bit keys and regedit 
    Dim reg64 As String = (Application.StartupPath() & "\64bit.reg") 
    Dim reg32 As String = (Application.StartupPath() & "\32bit.reg") 
    Dim regedit As String = "regedit.exe" 

    ' New ProcessStartInfo created 
    Dim p As New ProcessStartInfo 
    ' Specify the location of regedit 
    p.FileName = regedit 

    ' Checks the OS to see if it is x86 or x64 ' 
    If Environment.Is64BitOperatingSystem = True Then 

     ' Displays if the system OS is x64 ' 
     MessageBox.Show("This is an x64 system.") 

     ' Runs the 64 bit reg keys with the silent argument "/s" 
     p.Arguments = "/s """ & reg64 

     ' Start the process 
     Process.Start(p) 

     ' Displays if the system OS is x86 ' 
    Else : MessageBox.Show("This system is an x86 system.") 

     ' Runs the 32 bit reg keys with the silent argument "/s" 
     p.Arguments = "/s """ & reg32 

     ' Start the process 
     Process.Start(p) 

    End If 
관련 문제