Home Page Free Software CCTV Products CCTV Samples Local Services Offshore Services Contact Us

Computer Repair
Tel: 242-364-9183
Nassau, Bahamas
Bahamas Video Surveillance . Bahamas CCTV . Bahamas Infrared . Bahamas Digital Video . Bahamas Remote Video . Bahamas Burglar Alarm . Bahamas Technician
Bahamas Real Estate
Bahamas Yellow Pages


Free Software:


We Recommend:
MediaFire - Free File Hosting Made Simple
Follow us on:
Twitter Twitter


 

Add to Startup

Place your application at Windows XP Startup.
Download VB6 project. (7 downloads)

Alternative module based version available:
Download VB6 project. (9 downloads)

Form1.frm  - Example Form
Option Explicit

Private Sub cmdCheckVal_Click()
On Error GoTo Err:
    If Len(QueryValue(HKEY_LOCAL_MACHINE, _
    "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
    "My Program")) Then
        MsgBox "Value Exists"
    Else
        MsgBox "Value Does Not Exist"
    End If
    Exit Sub
Err:
    MsgBox "Check Value Error!"
    Exit Sub
End Sub

Private Sub cmdInstall_Click()
On Error GoTo Err:
    SaveString HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
    "My Program", "C:\Program Files\My Program\Something.exe"
        MsgBox "Added to Startup"
    Exit Sub
Err:
    MsgBox "Install Error!"
    Exit Sub
End Sub

Private Sub cmdRemove_Click()
On Error GoTo Err:
    DeleteValue HKEY_LOCAL_MACHINE, _
    "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
    "My Program"
        MsgBox "Removed from Startup"
    Exit Sub
Err:
    MsgBox "Remove Error!"
    Exit Sub
End Sub


modReg.bas - Registry Module

Option Explicit

Global Const REG_SZ As Long = 1
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const REG_DWORD As Long = 4
Global Const KEY_ALL_ACCESS = &H3F
Global Const ERROR_NONE = 0

Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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
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
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
Declare Function RegDeleteValue& Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String)
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
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
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

Public Function SetKeyValue(lPredefinedKey As Long, sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)
    Dim lRetVal As Long
    Dim hKey As Long
    lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
    RegCloseKey (hKey)
End Function

Public Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
    Dim lValue As Long
    Dim sValue As String
    Select Case lType
        Case REG_SZ
            sValue = vValue
            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

Public Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
   Dim KeyHand As Long
   Dim r As Long
   r = RegCreateKey(hKey, strPath, KeyHand)
   r = RegSetValueEx(KeyHand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
   r = RegCloseKey(KeyHand)
End Sub

Public Function DeleteValue(lPredefinedKey As Long, sKeyName As String, sValueName As String)
    Dim lRetVal As Long
    Dim hKey As Long
    lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lRetVal = RegDeleteValue(hKey, sValueName)
    RegCloseKey (hKey)
End Function

Public Function QueryValue(lPredefinedKey As Long, sKeyName As String, sValueName As String)
    Dim lRetVal As Long
    Dim hKey As Long
    Dim vValue As Variant
    lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lRetVal = QueryValueEx(hKey, sValueName, vValue)
    QueryValue = vValue
    RegCloseKey (hKey)
End Function

Public Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
    Dim cch As Long
    Dim lrc As Long
    Dim lType As Long
    Dim lValue As Long
    Dim sValue As String
    On Error GoTo QueryValueExError
    lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
    If lrc <> ERROR_NONE Then Error 5
    Select Case lType
        Case REG_SZ:
        sValue = String(cch, 0)
        lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
        If lrc = ERROR_NONE Then
            vValue = Left$(sValue, cch)
        Else
            vValue = Empty
        End If
    Case REG_DWORD:
        lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
        If lrc = ERROR_NONE Then vValue = lValue
    Case Else
        lrc = -1
    End Select
    
QueryValueExExit:
    QueryValueEx = lrc
    Exit Function
    
QueryValueExError:
    Resume QueryValueExExit

End Function

Bahamas CCTV . Bahamas DVR . Bahamas Camera . Bahamas Video . Bahamas Computer Repair . Bahamas Software . Bahamas Business . Bahamas Real Estate
Copyright (c) 2001/2010 BahamasSecurity.com