Hi nitika!
sorry, here is the whole example
The sub Test at the end creates an entry in the registry.
This should start the notepad one time after reboot!
Const ERROR_SUCCESS = 0&
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
Private Declare Function Reg_OpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function Reg_SetValueEx 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
Private Declare Function Reg_CloseKey Lib "advapi32.dll" Alias "RegCloseKey" (ByVal hKey As Long) As Long
Function MakeNullTerminated(ByVal str As String) As String
If Len(str) > 0 Then
If Right(str, 1) <> vbNullChar Then MakeNullTerminated = str & vbNullChar
Else
MakeNullTerminated = vbNullChar
End If
End Function
Function RegOpenKey(ByVal hKey As Long, ByVal SubKey As String, hResult As Long) As Boolean
SubKey = MakeNullTerminated(SubKey)
RegOpenKey = Reg_OpenKey(hKey, SubKey, hResult) = ERROR_SUCCESS
End Function
Function RegSetValueEx(ByVal hKey As Long, ByVal ValueName As String, ByVal StrValue As String) As Boolean
Dim StrLength As String
ValueName = MakeNullTerminated(ValueName)
StrValue = MakeNullTerminated(StrValue)
StrLength = Len(StrValue)
RegSetValueEx = Reg_SetValueEx(hKey, ValueName, 0, REG_SZ, ByVal StrValue, StrLength) = ERROR_SUCCESS
End Function
Public Function RegCloseKey(ByVal hKey As Long) As Boolean
RegCloseKey = Reg_CloseKey(hKey) = ERROR_SUCCESS
End Function
Sub Test()
Dim hKey As Long
If RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", hKey) Then
RegSetValueEx hKey, "Test", "notepad.exe"
RegCloseKey hKey
End If
End Sub
bye
LauDse