hung pro vn

[VB] Registry Operations

A central hierarchical database used in Microsoft Windows Operating System to store information that is necessary to configure the system for one or more users, applications and hardware devices.

The Registry comprises a number of logical sections called Hives. The following are the predefined keys that are used by the system.

  • HKEY_CURRENT_USER
  • HKEY_USERS
  • HKEY_LOCAL_MACHINE
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_CONFIG

Each key has many subkeys and may have a value.

When programming with VB.NET, you can choose to access the registry via either the functions provided by VB.NET or the registry classes of the .NET Framework. Registry entries contain two parts: the value name and the value.

Creating a Registry Entry


rKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
rKey.CreateSubKey("AppReg")


Above code shows how to create a subkey under HKLM\Software called AppReg.

Writing values to Registry

 
rKey.SetValue("AppName", "RegApp")
rKey.SetValue("Version", 1.1)


Above code shows how to set values to registry entry AppReg.

The following VB.NET program shows how to create a registry entry , set values to registry , retrieve values from registry and delete keys on Registry.Drag and drop four buttons on the form control and copy and paste the following source code.

FULL CODE EXAMPLTE :

Imports Microsoft.Win32
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim rKey As RegistryKey
		rKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
		rKey.CreateSubKey("AppReg")
		rKey.Close()
		MsgBox("AppReg created !")
	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Dim rKey As RegistryKey
		rKey = Registry.LocalMachine.OpenSubKey("Software\AppReg", True)
		rKey.SetValue("AppName", "RegApp")
		rKey.SetValue("Version", 1.1)
		rKey.Close()
		MsgBox("Appname , version created")
	End Sub

	Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
		Dim rKey As RegistryKey
		Dim ver As Decimal
		Dim app As String
		rKey = Registry.LocalMachine.OpenSubKey("Software\AppReg", True)
		app = rKey.GetValue("AppName")
		ver = rKey.GetValue("Version")
		rKey.Close()
		MsgBox("App Name  " & app & "  Version  " & ver.ToString)
	End Sub

	Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
		Dim rKey As RegistryKey
		rKey = Registry.LocalMachine.OpenSubKey("Software", True)
		rKey.DeleteSubKey("AppReg", True)
		rKey.Close()
		MsgBox("AppReg deleted")
	End Sub
End Class

Hướng dẫn bình luận

Mọi người để lại bình luận góp ý, nhận xét về những bài viết mà mình chia sẽ văn minh lịch sự hay kích động, Không spam, không chèn link quảng cáo, bán hàng, Không sử dụng từ ngữ thô tục, xúc phạm, kích động, Link chỉ được phép khi thực sự liên quan đến nội dung bài viết, Không mạo danh người khác hoặc sử dụng email giả, Bình luận vi phạm sẽ bị xóa không cần thông báo trước.
Mọi người lưu ý răng, nếu muốn chia sẽ code ở bình luần thì cần mã hóa code trước khi bỏ vào khung nhé. :)
⑴ Chèn ℂ𝕤𝕤 theo mẫu : [pre css] CSS [/pre]
⑵ Chèn ℍ𝕥𝕞𝕝 theo mẫu : [pre html] HTML [/pre]
⑶ Chèn 𝕁𝕒𝕧𝕒𝕤𝕔𝕣𝕚𝕡𝕥 theo mẫu : [pre js] Javascript [/pre]

🖼️ Chèn 𝕀𝕞𝕒𝕘𝕖 theo mẫu : [img] Link hình ảnh [/img]
🎞️ Chèn Video 𝕐𝕠𝕦𝕥𝕦𝕓𝕖 theo mẫu : [youtube] Link Youtube [/youtube]

13 Nhận xét

  1. What is the SOFTWARE item and where will it be located?

    Trả lờiXóa
    Trả lời
    1. Đây là đoạn code ghi chương trình của mình vào file hệ thống để làm nhiều việc khác đó nữa bạn.

      Vị dụ như bản quyền hay thông tin người dùng.

      Xóa
    2. Đúng r đó bạn #Tuân code trên là để tạo dữ liệu được in lên hệ thống của windows.

      Xóa
  2. Haha, nhìn lên thấy thông tin system này là bạn cũng hiểu rồi đó
    HKEY_CURRENT_USER
    HKEY_USERS
    HKEY_LOCAL_MACHINE
    HKEY_CLASSES_ROOT
    HKEY_CURRENT_CONFIG
    Một dạng ghi dữ liệu lên file hệ thống để tạo bản quyền hoặc dành cho cái ứng dụng được cài đặt lên windows để lấy thông số tự động và cập nhật bản quyền, thông số crack có sai lệch với thông tin lúc bạn cài đặt không để thông báo.

    Trả lờiXóa
  3. Nhìn source code cũng vui đấy nhưng mình không rỏ.

    Trả lờiXóa
  4. dễ bị crack nếu ng` dùng thông dụng windows, bữa này phần mềm tạo bản quyền hay làm gì đều kết nối cơ sỡ dữ liệu online để quản lý chương trình tốt nhất hiện nay :D

    Trả lờiXóa
    Trả lời
    1. Đúng rồi bạn, mình cũng đang tìm hiểu về vấn đề trên để viết chương trình bản quyền riêng của bản thân mình :D

      Xóa
  5. Minh đã test thử sao trong file system không có gì hết nhĩ :S
    không biết nó nằm ở đâu trong system này :
    HKEY_CURRENT_USER
    HKEY_USERS
    HKEY_LOCAL_MACHINE
    HKEY_CLASSES_ROOT
    HKEY_CURRENT_CONFIG

    Trả lờiXóa
  6. Bị lỗi nha mọi người.

    Trả lờiXóa
    Trả lời
    1. Vâng bị lỗi ở button 2 và button 3 nhé bạn.

      Xóa
  7. cái này có phải là ghi dữ liệu vào hệ thống windows để tạo bản quyền hay một số thứ khác không nhỉ

    Trả lờiXóa
  8. Cái này mình có chia sẽ bài viết bản quyền chương trình nhưng bị crack vì nó bị can thiệp hệ thống windows nhé. chương trình bản quyền 30 ngày nhưng thay đổi thời gian hệ thống là chương trình sữ dụng bình thương haha.

    Trả lờiXóa

Top