Results 1 to 3 of 3

Thread: Help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2001
    Location
    UK
    Posts
    158

    Help

    I need to run a programm when windows starts...

    a simple program.

    How do I do it ?

    Please help
    [vbcode] On Error GoTo VBForums[/vbcode]
    www27.brinkster.com/muditha

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Put this code under a Basic Module

    VB Code:
    1. Option Explicit
    2. Public Const HKEY_CLASSES_ROOT = &H80000000
    3. Public Const HKEY_CURRENT_USER = &H80000001
    4. Public Const HKEY_LOCAL_MACHINE = &H80000002
    5. Public Const HKEY_USERS = &H80000003
    6. Public Const HKEY_CURRENT_CONFIG = &H80000005
    7. Public Const HKEY_DYN_DATA = &H80000006
    8.  
    9. Private Const REG_SZ = 1 'Unicode nul terminated string
    10. Private Const REG_BINARY = 3 'Free form binary
    11. Private Const REG_DWORD = 4 '32-bit number
    12. Private Const ERROR_SUCCESS = 0& 'unusually registry API functions return 0 on success
    13.  
    14. Private Declare Function RegCloseKey Lib "advapi32.dll" _
    15. (ByVal hkey As Long) As Long
    16.  
    17. Private Declare Function RegCreateKey Lib "advapi32.dll" _
    18. Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey _
    19. As String, phkResult As Long) As Long
    20.  
    21. Private Declare Function RegSetValueEx Lib "advapi32.dll" _
    22. Alias "RegSetValueExA" (ByVal hkey As Long, ByVal _
    23. lpValueName As String, ByVal Reserved As Long, ByVal _
    24. dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    25.  
    26. Public Function RegSaveString(hkey As Long, strPath As String, _
    27.     strName As String, strData As String) As Boolean
    28.  
    29.  Dim hCurKey&
    30.  
    31.  If Right(strPath, 1) = "\" Then strPath = Left(strPath, Len(strPath) - 1)
    32.  
    33.  Call RegCreateKey(hkey, strPath, hCurKey)  'create key/open handle if already exists
    34.  RegSaveString = (RegSetValueEx(hCurKey, strName, 0, REG_SZ, _
    35.     ByVal strData, Len(strData)) = ERROR_SUCCESS) 'set value
    36.  Call RegCloseKey(hCurKey)  'close registry handle
    37. End Function


    Call the function anywhere in app
    VB Code:
    1. 'Add data into the registry
    2.  If RegSaveString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "MyAPP", REG_SZ, "C:\1.exe")  Then
    3.     MsgBox "Data saved"
    4.  Else
    5.     MsgBox "Fail to save"
    6.  End If

    Note:
    There different keys you can use are Run, runonce and RunService.
    Run: Runs everytime Windows starts
    runonce: Runs only once
    RunService: Runs much before normal Apps start (usually Anti-Virus programs start here)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2001
    Location
    UK
    Posts
    158
    Thaks man. I have another problem .....

    u can check it too.
    [vbcode] On Error GoTo VBForums[/vbcode]
    www27.brinkster.com/muditha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width