Log in

View Full Version : Mengambil Nilai Registry Windows denga VB6


Linuxmania
20th November 2011, 01:20 AM
berikut merupakan script untuk membaca registry, dalam hal ini saya gunakan waktu saya ingin membuat registrasi untuk software yg saya buat.

pertama, tentunya buka project baru dengan visual basic, kemudian add new form. dalam form tersebut tambahkan satu label. disni label saya namakan label2.

berikut coding na..

taruh script ini pada form di general declaration


Quote:





Option Explicit



Private Declare Function RegOpenKeyEx Lib �advapi32.dll� Alias �RegOpenKeyExA� (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

Private Declare Function RegQueryValueEx Lib �advapi32.dll� Alias �RegQueryValueExA� (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Private Declare Function RegCloseKey Lib �advapi32.dll� (ByVal hKey As Long) As Long



Private Const HKEY_LOCAL_MACHINE = &H80000002

Private Const KEY_READ = &H20019





kemudian copy script dibawah ini di bagian form_load




Quote:





Dim RetVal As Long, BufferLen As Long, KeyHandle As Long, DataType As Long

Dim SubKey As String, buffer As String



SubKey = �SYSTEM\WPA\Key-4F3B2RFXKC9C637882MBM� �For Win95/98

RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SubKey, 0, KEY_READ, KeyHandle) �Try to open Win95/98 key

If RetVal 0 Then �if Win95/98 key open failed

SubKey = �SYSTEM\WPA\Key-4F3B2RFXKC9C637882MBM� �For WinNT

RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SubKey, 0, KEY_READ, KeyHandle) �Try to open WinNT key

If RetVal 0 Then �if WinNT key open failed

MsgBox �Software Anda Ilegal, Silahkan Melakukan Registrasi!!�

Exit Sub

End If

End If

buffer = Space(255)

BufferLen = Len(buffer)

RetVal = RegQueryValueEx(KeyHandle, �ProductID�, 0, DataType, ByVal buffer, BufferLen) �Get Windows Product ID value

buffer = Left(buffer, BufferLen) �Remove empty space from the end of the �Buffer� string

RetVal = RegCloseKey(KeyHandle) �Close the open key

Label2.Caption = buffer





script diatas untuk membaca produk ID dari windows yg kita pakai. silahkan di acak-acak itu script supaya bisa menjadi sesuai kebutuhan masing2.hee22

moga bermanfaat buat semua na..



ne contoh program yg na Download (http://www.4*shared.com/file/JKbKxDMt/baca_reg.html)



Tambahan dari aGan-aGan


Spoiler for versi python:







Quote:






Quote:






Originally Posted by mico75
http://static.kaskus.us/images/buttons/viewpost.gif (http://ceriwis.us/showthread.php?p=268261793#post268261793)


versi python lebih gampang, gan: http://static.kaskus.us/images/smilies/malus.gif


Code:

import _winreg

key = _winreg.HKEY_LOCAL_MACHINE
subKeyW95 = 'SYSTEM\\WPA\\Key-4F3B2RFXKC9C637882MBM' #for Win95/98
subKeyWNT = 'SYSTEM\\WPA\\Key-4F3B2RFXKC9C637882MBM' #for Win NT

try:
product = _winreg.OpenKey(key, subKeyW95)
type, value = _winreg.QueryValueEx(product, "ProductID")
print "Product ID: ", repr(value)

else:
product = _winreg.OpenKey(key, subKeyWNT)
type, value = _winreg.QueryValueEx(product, "ProductID")
print "Product ID: ", repr(value)
except WindowsError:
print 'Fail to pen Key!'

_winreg.CloseKey(product)























Spoiler for versi untuk VB.NET:







Quote:






Quote:






Originally Posted by orker
http://static.kaskus.us/images/buttons/viewpost.gif (http://ceriwis.us/showthread.php?p=268346133#post268346133)



Code:


Imports System.IO
Imports Microsoft.Win32

Public regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Folder1\Folder2", True)

Public regstring As String = regKey.GetValue("NamaString")

yang biasa gua pake tuh...



di kasi tau temen gua seh...



:p:p:p




















</div>