PDA

Click to See Complete Forum and Search --> : Registry...?????


vbAlex
Nov 3rd, 1999, 08:37 PM
I want to make a dir in the registry with some keys for programm settings, but i want it on "hkey_localmachine\software\timer" (timer = programm's name...).

this doesn't work with the savesettings-function (only hkey_currentuser\software\vb and vba program\timer ........)

is there a OCX or somethiny else, that could help me ?
thanx for help

vbAlex

Mark Sreeves
Nov 3rd, 1999, 08:59 PM
email me directly

------------------
Mark Sreeves
Analyst Programmer

Mark.Sreeves@Softlab.co.uk
A BMW Group Company

Serge
Nov 3rd, 1999, 09:22 PM
Sure thing:


Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private 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
Private 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
Private 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
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long

Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
Private Const KEY_SET_VALUE = &H2
Private Const ERROR_SUCCESS = 0&
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

Public Sub SaveProgram(pHive As Long, pKeyName As String, pProgramName As String)
Dim lKeyHandle As Long
Dim lRet As Long
Dim strValue As String
Dim strKey As String
Dim sec As SECURITY_ATTRIBUTES
Dim lDummy As Long

sec.nLength = Len(sec)
strKey = "Software\Timer"
strValue = "MyProgram"
lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, vbNullString, 0, KEY_SET_VALUE, sec, lKeyHandle, lDummy)
If lRet <> ERROR_SUCCESS Then
MsgBox "Error creating a KEY", vbCritical
Exit Sub
End If
RegCloseKey lKeyHandle
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_SET_VALUE, lKeyHandle)
If lRet = ERROR_SUCCESS Then
lRet = RegSetValueEx(lKeyHandle, strValue, 0, REG_SZ, ByVal "", 1)
RegCloseKey lKeyHandle
End If
End Sub



Usage: SaveProgram KEYROOT, KeyValue, ProgramName

Example: SaveProgram HKEY_LOCAL_MACHINE, "Software\Timer", "MyProgram"


Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com

vbAlex
Nov 4th, 1999, 12:04 AM
thanx!