|
-
Feb 10th, 2003, 08:23 AM
#1
Thread Starter
Hyperactive Member
stupid values given from Registry Code
hi,
I'm using VB.NET to edited the registry and when I try to add a string to the registry the value ends up encrypted (or thats what it looks like)
when I set the value to be any thing it gives me a ä for some reason.
heres the code I'm using:
Module:
VB Code:
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Integer) As Integer
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA"(ByVal HKEY As Integer, ByVal lpSubKey As String, ByRef phkResult As Integer) As Integer
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA"(ByVal HKEY As Integer, ByVal lpSubKey As String) As Integer
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA"(ByVal HKEY As Integer, ByVal lpValueName As String) As Integer
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"(ByVal HKEY As Integer, ByVal lpSubKey As String, ByRef phkResult As Integer) As Integer
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal lpReserved As Integer, ByRef lpType As Integer, ByRef lpData As String, ByRef lpcbData As Integer) As Integer
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal lpReserved As Integer, ByRef lpType As Integer, ByRef lpData As Integer, ByRef lpcbData As Integer) As Integer
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal Reserved As Integer, ByVal dwType As Integer, ByRef lpData As String, ByVal cbData As Integer) As Integer
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal Reserved As Integer, ByVal dwType As Integer, ByRef lpData As Integer, ByVal cbData As Integer) As Integer
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const REG_SZ = 1
Function RegQueryStringValue(ByVal HKEY As Integer, ByVal strValueName As String) As Object
Dim ERROR_SUCCESS As Object
Dim lResult As Integer
Dim lValueType As Integer
Dim strBuf As String
Dim lDataBufSize As Integer
On Error GoTo 0
lResult = RegQueryValueEx(HKEY, strValueName, 0, lValueType, 0, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuf = New String(" ", lDataBufSize)
lResult = RegQueryValueEx(HKEY, strValueName, 0, 0, strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
RegQueryStringValue = StripTerminator(strBuf)
End If
End If
End If
End Function
Public Function GetSettingEx(ByRef HKEY As Integer, ByRef sPath As String, ByRef sValue As String) As Object
Dim KeyHand As Integer
Dim datatype As Integer
Call RegOpenKey(HKEY, sPath, KeyHand)
GetSettingEx = RegQueryStringValue(KeyHand, sValue)
Call RegCloseKey(KeyHand)
End Function
Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Short
intZeroPos = InStr(strString, Chr(0))
If intZeroPos > 0 Then
StripTerminator = Left(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Public Sub SaveSettingEx(ByRef HKEY As Integer, ByRef sPath As String, ByRef sValue As String, ByRef sData As String)
Dim KeyHand As Integer
Call RegCreateKey(HKEY, sPath, KeyHand)
Call RegSetValueEx(KeyHand, sValue, 0, REG_SZ, sData, Len(sData))
Call RegCloseKey(KeyHand)
End Sub
Form:
VB Code:
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
SaveSettingEx(HKEY_LOCAL_MACHINE, "Software\Studz\", "test", "1")
end sub
Is there anything wrong with mycode?
any help would be great.
thanks
Last edited by §tudz; Feb 10th, 2003 at 12:48 PM.
-
Feb 10th, 2003, 04:45 PM
#2
Sleep mode
Well , you have an attractive Class to use !It has all methods that you need to do all operations against the Registry .
have a look at this tutorial !
-
Feb 11th, 2003, 03:41 PM
#3
Thread Starter
Hyperactive Member
thanks for that, I take a look and see what I can do with it.
Do you know what is wrong with my Class?
Thanks
-
Feb 11th, 2003, 03:46 PM
#4
Sleep mode
I've not looked at it but , you seem still using API although you have the best alternative which is the Registry Class !
-
Feb 11th, 2003, 03:51 PM
#5
Thread Starter
Hyperactive Member
ok,
that doesn't work at all?
could it be something to do with using WinXP Pro?
-
Feb 11th, 2003, 03:53 PM
#6
Thread Starter
Hyperactive Member
No matter, that problem was I put the delete Key function in, so when it made the striong it then deleted it...
DUH!! I'm stupid some times 
Thanxs for the help
-
Feb 11th, 2003, 03:54 PM
#7
Sleep mode
-
Feb 11th, 2003, 09:01 PM
#8
PowerPoster
PLEASE tell me you are NOT using the code you posted above!!!!!!!!!!!! PLEASE I BEG YOU, use the built in registry objects under the Microsoft namespace. You will laugh when you realize how easy it is.
-
Feb 11th, 2003, 10:48 PM
#9
Sleep mode
lol ... .I think he still .
-
Feb 12th, 2003, 04:20 AM
#10
Thread Starter
Hyperactive Member
no, I'm using the built in class now. I just left the string delete value in, form the example.
just a query, what was wrong with my class? why did it produce incorrect values?
-
Feb 12th, 2003, 12:50 PM
#11
Sleep mode
I don't know but I think the consts are have values that can be applied to the win98 , me Registries !maybe not !
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
|