|
-
Oct 5th, 2001, 03:59 AM
#1
Thread Starter
Member
Registry
I want to add a new "string value" for a specified entry in the registry.
Under HKEY_LOCAL_MACHINE i have SOFTWARE under it i have say TEMP now i want to add a new "string value" say DirPath under this TEMP
and set the value for DirPath= "c:\TEMP"
how to do this. Ithink it can be done using some API.
-
Oct 5th, 2001, 04:24 AM
#2
Fanatic Member
Try this api
RegCreateKeyEx ()
-
Oct 5th, 2001, 04:28 AM
#3
Fanatic Member
Use this api to create the key RegCreateKeyEx()
Use this api to set the string value in the created key RegSetValueEx()
-
Oct 5th, 2001, 05:51 AM
#4
Thread Starter
Member
Thanks for ur help.
can u pls give some example.
-
Oct 5th, 2001, 06:30 AM
#5
Fanatic Member
here goes the code
' copy this code in your bas file
Global Const HKEY_CLASSES_ROOT = &H80000000
Global Const HKEY_CURRENT_CONFIG = &H80000005
Global Const HKEY_CURRENT_USER = &H80000001
Global Const HKEY_DYN_DATA = &H80000006
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const HKEY_PERFORMANCE_DATA = &H80000004
Global Const HKEY_USERS = &H80000003
Global Const KEY_ALL_ACCESS = &HF003F
Global Const KEY_CREATE_LINK = &H20
Global Const KEY_CREATE_SUB_KEY = &H4
Global Const KEY_ENUMERATE_SUB_KEYS = &H8
Global Const KEY_EXECUTE = &H20019
Global Const KEY_NOTIFY = &H10
Global Const KEY_QUERY_VALUE = &H1
Global Const KEY_READ = &H20019
Global Const KEY_SET_VALUE = &H2
Global Const KEY_WRITE = &H20006
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public 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
Public 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
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const REG_SZ = 1
'copy this code in your form
' add a button to it...
Private Sub Command1_Click()
Dim hKey As Long ' receives handle to the registry key
Dim secattr As SECURITY_ATTRIBUTES ' security settings for the key
Dim subkey As String ' name of the subkey to create or open
Dim neworused As Long ' receives flag for if the key was created or opened
Dim stringbuffer As String ' the string to put into the registry
Dim retval As Long ' return value
' Set the name of the new key and the default security settings
subkey = "Software\pradeep"
secattr.nLength = Len(secattr)
secattr.lpSecurityDescriptor = 0
secattr.bInheritHandle = 1
' Create (or open) the registry key.
retval = RegCreateKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, "", 0, KEY_WRITE, _
secattr, hKey, neworused)
If retval <> 0 Then
Debug.Print "Error opening or creating registry key -- aborting."
Exit Sub
End If
' Write the string to the registry. Note the use of ByVal in the second-to-last
' parameter because we are passing a string.
stringbuffer = "Pradeep" & vbNullChar ' the terminating null is necessary
retval = RegSetValueEx(hKey, "username", 0, REG_SZ, ByVal stringbuffer, _
Len(stringbuffer))
' Close the registry key.
retval = RegCloseKey(hKey)
End Sub
-
Oct 5th, 2001, 09:12 AM
#6
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|