Valhalla Legends Forums Archive | Visual Basic Programming | Run at Startup & Registry

AuthorMessageTime
Dyndrilliac
I seem to have hit a snag. For some reason when I use:
[code]AddToRun("Omega Loader", App.Path + "\" + App.EXEName)[/code]
I get [quote]"Compile Error! Expected: ="[/quote]
But I shouldn't need an "=" in there. Heres what I have in my Module:[code]Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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
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

Const ERROR_SUCCESS = 0&
Const REG_SZ = 1 ' Unicode nul terminated String
Const REG_DWORD = 4 ' 32-bit number

Public Enum HKeyTypes
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
End Enum

Public Sub AddToRun(ProgramName As String, FileToRun As String)
'Add a program to the 'Run at Startup' registry keys
Call SaveString(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", ProgramName, FileToRun)
End Sub

Public Sub SaveKey(Hkey As HKeyTypes, strPath As String)
Dim keyhand&
r = RegCreateKey(Hkey, strPath, keyhand&)
r = RegCloseKey(keyhand&)
End Sub

Public Sub SaveString(Hkey As HKeyTypes, 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[/code]

As you can imagine, I am perplexed.

Edit: I also have:[code]Dim VarAddRemove As New AddRemove[/code]In my Form Declarations and:[code]Set VarAddRemove = New AddRemove[/code]In my Form Load procedure.
November 27, 2003, 9:42 PM
MesiaH
Remove your parentheses.

Make it, AddToRun "0mega Loader", App.path + "\" + App.EXEName
November 27, 2003, 9:45 PM
Dyndrilliac
Thanks :D
November 27, 2003, 9:46 PM
Puzzle
A quick tip: make it a habbit to use the & operator instead of + because VB tends to try to use the + as a mathematical operator.
November 29, 2003, 2:02 AM

Search