VB.NET 2008/VB - 리소스 액세스

컴퓨터 리소스 액세스 - 레지스트리 읽기 및 쓰기

본클라쓰 2011. 5. 25. 11:04

My.Computer.Registry 개체는 레지스트리에 액세스하기 위한 속성과 메서드를 제공한다.

 

 

My.Computer.Registry 개체의 CreateSubKey 메서드를 사용하여 레지스트리 키를 만들 수 있다. CreateSubKey 메서드에 키를 배치할 상위 하이브와 키 이름을 지정한다. CreateSubKey 매개 변수는 대/소문자를 구분하지 않는다. 다음 예제는 HKEY_CURRENT_USER 아래에 MyTestKey 레지스트리 키를 만든다.

 

My.Computer.Registry.CurrentUser.CreateSubKey("MyTestKey")

 

레지스트리 키를 만들고 키 값을 설정하려면 SetValue 메서드를 사용하여 값을 설정한다.

 

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

 

 

레지스트리 키에 값이 있는지 확인하려면, GetValue 메서드를 사용하여 해당 값을 가져온다.

 

If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\TestApp", "TestValue", Nothing) Is Nothing Then
    MsgBox("Value does not exist.")
End If

 

레지스트리 키에서 값을 읽으려면, GetValue 메서드에 경로와 이름을 지정하여 레지스트리 키에서 값을 읽는다.

 

Dim readValue As String
readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\MyApp", "Name", Nothing)
MsgBox("The value is " & readValue)

 

레지스트리 키를 삭제하려면, DeleteSubKey 메서드를 사용하여 레지스트리 키를 삭제한다.

 

My.Computer.Registry.CurrentUser.DeleteSubKey(text)