Results 1 to 5 of 5

Thread: [VB] Autostart

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    [VB] Autostart

    VB Code:
    1. Option Explicit
    2.  
    3. 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
    4.  
    5.     ' Reg Key Security Options...
    6.     Const READ_CONTROL = &H20000
    7.     Const KEY_QUERY_VALUE = &H1
    8.     Const KEY_SET_VALUE = &H2
    9.     Const KEY_CREATE_SUB_KEY = &H4
    10.     Const KEY_ENUMERATE_SUB_KEYS = &H8
    11.     Const KEY_NOTIFY = &H10
    12.     Const KEY_CREATE_LINK = &H20
    13.  
    14.     ' Reg Key ROOT Types...
    15.     Const HKEY_LOCAL_MACHINE = &H80000002
    16.     Const ERROR_SUCCESS = 0
    17.     Const REG_SZ = 1                         ' Unicode nul terminated string
    18.     Const REG_DWORD = 4                      ' 32-bit number
    19.  
    20.     Const gREGKEYSYSINFOLOC = "SOFTWARE\Microsoft\Shared Tools Location"
    21.     Const gREGVALSYSINFOLOC = "MSINFO"
    22.     Const gREGKEYSYSINFO = "SOFTWARE\Microsoft\Shared Tools\MSINFO"
    23.     Const gREGVALSYSINFO = "PATH"
    24.  
    25. Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
    26. Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
    27. Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
    28. Private Const HKEY_CLASSES_ROOT = &H80000000
    29. Private Const HKEY_CURRENT_USER = &H80000001
    30. Private Const HKEY_USERS = &H80000003
    31. Private Const HKEY_PERFORMANCE_DATA = &H80000004
    32.  
    33.  
    34. Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    35. Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    36. Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    37. Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    38.  
    39.  
    40.     Const HKEY_DYN_DATA = &H80000006
    41.     Const REG_BINARY = 3
    42.     Const REG_DWORD_BIG_ENDIAN = 5
    43.     Const REG_DWORD_LITTLE_ENDIAN = 4
    44.     Const REG_EXPAND_SZ = 2
    45.     Const REG_LINK = 6
    46.     Const REG_MULTI_SZ = 7
    47.     Const REG_NONE = 0
    48.     Const REG_RESOURCE_LIST = 8
    49.  
    50. Function StripTerminator(ByVal strString As String) As String
    51.  Dim intZeroPos As Integer
    52.  intZeroPos = InStr(strString, Chr$(0))
    53.  If intZeroPos > 0 Then
    54.     StripTerminator = Left$(strString, intZeroPos - 1)
    55.  Else
    56.     StripTerminator = strString
    57.  End If
    58. End Function
    59.  
    60. Private Sub savestring(ByVal hKey As Long, ByVal strpath As String, ByVal strvalue As String, ByVal strdata As String)
    61.  Dim keyhand&, r#
    62.  r = RegCreateKey(hKey, strpath, keyhand&)
    63.  r = RegSetValueEx(keyhand&, strvalue, 0, REG_SZ, ByVal strdata, Len(strdata))
    64.  r = RegCloseKey(keyhand&)
    65. End Sub
    66.  
    67. Public Sub CreateStartupKey()
    68.     savestring HKEY_LOCAL_MACHINE, "\Software\Microsoft\Windows\CurrentVersion\Run", App.Title, App.Path & "\" & App.EXEName & ".exe"
    69. End Sub
    Last edited by RobDog888; Jan 10th, 2008 at 01:45 PM.

  2. #2
    Banned
    Join Date
    Jan 2008
    Posts
    49

    Re: [VB] Autostart

    Code didn't work for me...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Re: [VB] Autostart

    It was written for XP I believe. I posted it on Feb 2nd, 2004. I am nearly sure it worked for me at the time.

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [VB] Autostart

    you have to have administrator access for it to work. Also, the key changes for each logged on user.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [VB] Autostart

    Highlight code tags added to make the code easier to read.

    Yes, permissions to access /rea / wrote to the registry is needed as most limited user accounts wont be able to use the registry.

    @C0LZ4, can you say more then "doesnt work"?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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