Warung Bebas

Kamis, 09 Mei 2013

Enable/Disable Registry Editor

Ini lagi sebuah kode program VB 6.0 (Visual Basic 6.0) untuk Enable/Disable Registry Editor Windows. Registry Windows sendiri merupakan tempat penyimpanan informasi hardware ataupun software yang terpasang pada komputer/laptop.
Oleh karena itu Registry Editor ini sangat rentan terhadap serangan hacker karena disanalah tempat yang paling penting seperti tempat penyimpanan memori pada otak manusia. Ok, jangan bertele-tele lagi langsung saja ke TKP.

Berikut langkah pembuatannya.
  1. Buat Projct baru VB 6.0 pada komputer Anda.
  2. Pada Form yang aktif tambahkan 2 Commandbutton.
  3. Atur Properties Commanbutton masing-masing dengan Caption=Enable Registry Editor dan Caption=Disable Registry Editor.
  4. Tambahkan 1 Module dengan cara pilih menu Project --> Add Module. Masukkan kode di bawah ini ke dalam Module.
  5. Option Explicit

    Public Enum RegType
    REG_SZ = 1
    REG_DWORD = 4
    End Enum

    Public Enum BaseKeys
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_USER = &H80000001
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_USERS = &H80000003
    End Enum

    Private Const ERROR_NONE = 0
    Private Const ERROR_BADDB = 1
    Private Const ERROR_BADKEY = 2
    Private Const ERROR_CANTOPEN = 3
    Private Const ERROR_CANTREAD = 4
    Private Const ERROR_CANTWRITE = 5
    Private Const ERROR_OUTOFMEMORY = 6
    Private Const ERROR_ARENA_TRASHED = 7
    Private Const ERROR_ACCESS_DENIED = 8
    Private Const ERROR_INVALID_PARAMETERS = 87
    Private Const ERROR_NO_MORE_ITEMS = 259

    Private Const KEY_ALL_ACCESS = &H3F
    Private Const KEY_QUERY_VALUE = &H1


    Private Const REG_OPTION_NON_VOLATILE = 0

    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
    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 RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
    Private Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
    Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
    Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
    Private Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
    Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long



    Sub CreateNewKey(sNewKeyName As String, lPredefinedKey As BaseKeys)
    'Purpose: create a new regestry key
    'Parameters: sNewKeyName - name of regestry key to be created, string
    ' lPredefinedKey - location to create new key in regestry, BaseKeys
    Dim hNewKey As Long 'handle to the new key
    Dim lRetVal As Long 'result of the RegCreateKeyEx function
    lRetVal = RegCreateKeyEx(lPredefinedKey, sNewKeyName, 0&, _
    vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hNewKey, lRetVal)
    RegCloseKey (hNewKey)
    End Sub

    Sub SetKeyValue(lPredefinedKey As BaseKeys, sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As RegType)
    'Purpose: set value of existing key
    'Parameters: lPredefinedKey - location of registry key, BaseKeys
    ' sKeyName - name of key to set value in, string
    ' sValueName - name of regestry value to be set, string
    ' vValueSetting - value to be set, variant
    ' lValueType - type of value to set into registry, RegType
    Dim lRetVal As Long 'result of the SetValueEx function
    Dim hKey As Long 'handle of open key
    'open the specified key
    lRetVal = RegCreateKeyEx(lPredefinedKey, sKeyName, 0&, _
    vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hKey, lRetVal)
    ' lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
    RegCloseKey (hKey)
    End Sub

    Function QueryValue(lPredefinedKey As BaseKeys, sKeyName As String, sValueName As String, Optional sDefaultValue As Variant) As Variant
    'Purpose: rerieve value from regestry
    'Parameters: lPredefinedKey - location of registry key, BaseKeys
    ' sKeyName - name of key to set value in, string
    ' sValueName - name of regestry value to be set, string
    ' sDefaultValue - if bad value or no value at key this is returned, variant, optional
    On Error GoTo ErrorHandler
    If IsMissing(sDefaultValue) Then sDefaultValue = ""
    Dim lRetVal As Long 'result of the API functions
    Dim hKey As Long 'handle of opened key
    Dim vValue As Variant 'setting of queried value

    lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_QUERY_VALUE, hKey)
    'lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    'lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lRetVal = QueryValueEx(hKey, sValueName, vValue)
    If lRetVal = ERROR_BADKEY Then QueryValue = sDefaultValue
    RegCloseKey (hKey)
    If IsEmpty(vValue) Then
    QueryValue = sDefaultValue
    Else
    QueryValue = vValue
    End If
    Exit Function
    ErrorHandler:
    QueryValue = sDefaultValue
    End Function



    'SetValueEx and QueryValueEx Wrapper Functions:
    Private Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
    'Purpose: set a value to the registry
    'Parameters: hKey - registry key to set, long
    ' sValueName - name of registry value to set, string
    ' lType - type used in registry value, long
    ' vValue - value to be place in regestry, variant
    Dim lValue As Long
    Dim sValue As String
    Select Case lType
    Case REG_SZ
    sValue = vValue & Chr$(0)
    SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
    Case REG_DWORD
    lValue = vValue
    SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
    End Select
    End Function

    Private Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
    'Purpose: get a value from the registry
    'Parameters: lhKey - regestry key to get, long
    ' szValueName - name of registry value to get, string
    ' vValue - registry value to get, value
    Dim cch As Long
    Dim lrc As Long
    Dim lType As Long
    Dim lValue As Long
    Dim sValue As String

    ' On Error GoTo QueryValueExError

    ' Determine the size and type of data to be read
    lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
    ' If lrc <> ERROR_NONE Then Error 5

    Select Case lType
    ' For strings
    Case REG_SZ:
    sValue = String(cch, 0)
    lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
    If lrc = ERROR_NONE Then
    vValue = Left$(sValue, cch - 1)
    Else
    vValue = Empty
    End If
    ' For DWORDS
    Case REG_DWORD:
    lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
    If lrc = ERROR_NONE Then vValue = lValue
    Case Else
    'all other data types not supported
    lrc = -1
    End Select

    QueryValueExExit:
    QueryValueEx = lrc
    Exit Function
    QueryValueExError:
    Resume QueryValueExExit
    End Function

    Function DeleteKey(lPredefinedKey As BaseKeys, strKey As String)
    RegDeleteKey lPredefinedKey, strKey
    End Function

    Function DeleteValue(lPredefinedKey As BaseKeys, strKey As String, strVal As String)
    Dim lRetVal, hKey As Long
    lRetVal = RegOpenKeyEx(lPredefinedKey, strKey, 0, KEY_ALL_ACCESS, hKey)
    lRetVal = RegDeleteValue(hKey, strVal)
    RegCloseKey (hKey)
    End Function
  6. Pada Form deklarasikan Function di bawah ini.
  7. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  8. Masukkan kode di bawah ini untuk pada form untuk menonaktifkan registry.
  9. SetKeyValue HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableRegistryTools", "1", REG_DWORD
    MsgBox "Disabled Registry", vbInformation
  10. Masukkan kode di bawah ini untuk pada form untuk mengaktifkan registry.
  11. SetKeyValue HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableRegistryTools", "0", REG_DWORD
    MsgBox "Enabled Registry", vbInformation
  12. Jalankan dan lihat hasilnya. Selesai.
Untuk mendownload contoh programnya disini atau disini.

0 komentar em “Enable/Disable Registry Editor”

Posting Komentar

 

Indah Hidup Copyright © 2012 Fast Loading -- Powered by Blogger