|
-
Jul 29th, 2007, 12:57 PM
#1
Thread Starter
Fanatic Member
Reading and Writing and Deleting from registry
I need to read and write from the registry as well as deleting entrys. Anyone got a simple example on how to do it.
I also need to know which encryption method I should use to store passwords in the registry?
Last edited by psychotomus; Jul 29th, 2007 at 01:01 PM.
-
Jul 29th, 2007, 02:12 PM
#2
Addicted Member
Re: Reading and Writing and Deleting from registry
Mentalis has a good example.
-
Jul 29th, 2007, 02:27 PM
#3
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
Doesn't show how to create sub-directorys in the registry. Do I just add the / for the path?
like
vb Code:
RegCreateKeyEx HKEY_CURRENT_USER, "Sim-Chat", 0, "REG_DWORD", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, Result, Ret
RegCreateKeyEx HKEY_CURRENT_USER, "Sim-Chat/Users", 0, "REG_DWORD", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, Result, Ret
guess i'll give it a try. bbl. =)
-
Jul 29th, 2007, 06:12 PM
#4
Addicted Member
Re: Reading and Writing and Deleting from registry
Use this..."\"...not "/".
Other thing..I recommend in order to write REG_DWORD values to use this code style example:
vb Code:
Public Function WriteRegDWORD(ByVal h_Key As Long, ByVal lpcszPath As String, ByVal lpcszField As String, ByVal dwData As Long) As Boolean
Dim hKey As Long
Dim bRet As Boolean
If RegCreateKeyEx(h_Key, lpcszPath, 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, hKey, 0) <> ERROR_SUCCESS Then
WriteRegDWORD = False
Else
If RegSetValueEx(hKey, lpcszField, 0, REG_DWORD, dwData, Len(dwData)) = ERROR_SUCCESS Then
bRet = True
Else
bRet = False
End If
RegCloseKey hKey
End If
WriteRegDWORD = bRet
End Function
To use something like this:
vb Code:
WriteRegDWORD HKEY_LOCAL_MACHINE, "Software\Joel", "dwValueToWrite", 69
Remember: this is an example..change it according to your needs.
-
Jul 29th, 2007, 07:07 PM
#5
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
Thanks Kal. Great example.
-
Jul 29th, 2007, 07:50 PM
#6
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
I keep getting a type mismatch and can't figure out why. I copyed your function line for line =). any ideas why? I also have all constants and api functions correct.
vb Code:
If chkSavePassword.Value = vbChecked Then
If WriteRegDWORD(HKEY_LOCAL_MACHINE, "Software\Sim-Chat\Users\" & MyUserName & "\Login", "Password", txtPassword.Text) = False Then
MsgBox "error"
End If
Else
If WriteRegDWORD(HKEY_LOCAL_MACHINE, "Software\Sim-Chat\Users\" & MyUserName & "\Login", "Password", "") = False Then
MsgBox "error"
End If
End If
-
Jul 29th, 2007, 10:11 PM
#7
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
-
Jul 29th, 2007, 10:37 PM
#8
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
We'll I thought I had it. Now I cant insert value's into the Keys. =(
-
Jul 29th, 2007, 10:49 PM
#9
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
nevermind. got that fixed now too. kek
-
Jul 30th, 2007, 03:04 PM
#10
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
Now I can't read my values.
Code:
Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
Dim strData As Integer
'retrieve nformation about the key
lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
If lResult = 0 Then
If lValueType = REG_SZ Then
'Create a buffer
strBuf = String(lDataBufSize, Chr$(0))
'retrieve the key's content
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
'Remove the unnecessary chr$(0)'s
RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
End If
ElseIf lValueType = REG_BINARY Then
'retrieve the key's value
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
ElseIf lValueType = REG_DWORD Then
'retrieve the key's value
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
End If
End If
End Function
my lValueType is a DWORD. returns a #.
-
Jul 30th, 2007, 06:46 PM
#11
Addicted Member
Re: Reading and Writing and Deleting from registry
When reading values you must use RegOpenKeyEx.
-
Jul 30th, 2007, 08:02 PM
#12
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
Code:
Function ReadRegDWORD(path As String) As Long
RegOpenKeyEx HKEY_CURRENT_USER, path, 0, KEY_ALL_ACCESS, ReadRegDWORD
End Function
I must be missing something here. keeps returning 0 when i use
ReadRegDWORD ("Software\Sim-Chat\Users\" & cmbUserName.Text & "\Login\Password") Where Password is the DWORD and not a Key
if I use
ReadRegDWORD ("Software\Sim-Chat\Users\" & cmbUserName.Text & "\Login")
it returns a #
-
Jul 31st, 2007, 08:55 AM
#13
Addicted Member
Re: Reading and Writing and Deleting from registry
No, sir....RegOpenKeyEx is only step one of three:
RegOpenKeyEx
RegQueryValueEx
RegCloseKey
See an example.
Also try google sometime
-
Jul 31st, 2007, 02:55 PM
#14
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
1 last question. swear =)
WHen it inserts the data into the registry. it encrypts it and when I receive it, it doesnt decrypt it. How am I suppose to decrypt it?
-
Jul 31st, 2007, 06:52 PM
#15
Addicted Member
Re: Reading and Writing and Deleting from registry
Ok..
Windows encrypts registry values for security reasons..but using the advapi functions like RegQueryValueEx, you shouldn't botther decrypt them your self.
If you want to encrypt entries you'll have to write your own algorithm for encrypt and decrypt.
-
Jul 31st, 2007, 09:38 PM
#16
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
no. what i'm saying is when I insert a value into the registry, it encrypts it. but when I use RegQueryValueEx. it returns the encrypted entry, it doesn't decrypt it.
-
Jul 31st, 2007, 09:55 PM
#17
Addicted Member
Re: Reading and Writing and Deleting from registry
 Originally Posted by psychotomus
no. what i'm saying is when I insert a value into the registry, it encrypts it. but when I use RegQueryValueEx. it returns the encrypted entry, it doesn't decrypt it.
Wait! That's no true!
You must getting wrong values or something went wrong...
-
Aug 10th, 2007, 11:40 PM
#18
Re: Reading and Writing and Deleting from registry
Wow you guys are doing it the hard way. All you need to use is this code. Put this in the declarations section
Code:
Dim SScript
Set SScript = CreateObject("WScript.Shell")
To write to the registry
Code:
SScript.RegWrite "KEY", "DATA"
To read:
Code:
label1.caption=SScript.RegRead("KEY")
(I do not take credit for this code. Jazz00006 posted this on another site)
If a post has been helpful please rate it. 
If your question has been answered, pull down the tread tools and mark it as resolved.
-
Aug 10th, 2007, 11:44 PM
#19
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
 Originally Posted by Mxjerrett
Wow you guys are doing it the hard way. All you need to use is this code. Put this in the declarations section
Code:
Dim SScript
Set SScript = CreateObject("WScript.Shell")
To write to the registry
Code:
SScript.RegWrite "KEY", "DATA"
To read:
Code:
label1.caption=SScript.RegRead("KEY")
(I do not take credit for this code. Jazz00006 posted this on another site)
where at does it write that data at in the registry?
-
Aug 11th, 2007, 12:00 AM
#20
Re: Reading and Writing and Deleting from registry
SScript.RegWrite "KEY", "DATA" writes it to the registry. Replace KEY with the location and DATA with the data you want to supply.
If a post has been helpful please rate it. 
If your question has been answered, pull down the tread tools and mark it as resolved.
-
Aug 11th, 2007, 01:04 AM
#21
Thread Starter
Fanatic Member
Re: Reading and Writing and Deleting from registry
where at in the registry i am asking?
-
Aug 11th, 2007, 11:00 AM
#22
Re: Reading and Writing and Deleting from registry
Where ever you specify. You replace KEY with where you want it and wallah, your data is displayed in the registry, where ever you told it to.
If a post has been helpful please rate it. 
If your question has been answered, pull down the tread tools and mark it as resolved.
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
|