Solved

RegSetValueEx error

Posted on 2003-11-03
9
1,846 Views
Last Modified: 2007-12-19
I'm trying to write data to the registry using this function and it keeps returning error code 1450 (insufficient resources). Anyone know what would cause this?

My function looks like:

Public Function SaveSetting(ByVal Section as String, ByVal Key As String, ByVal Setting as String) as Boolean

   Dim nRet as Long
   Dim hKey as Long
   Dim nResult as Long
   
   nRet = RegCreateKeyEx(HKEY_CURRENT_USER, SubKey(Section), 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, hKey, nResult)

   If nRet = ERROR_SUCCESS Then
      If Key = "*" then Key = vbNullString
      nRet = RegSetValueEx(hKey, Key, 0&, REG_SZ, ByVal Setting, Len(Setting)) '<- here's where I get the error
      Call RegCloseKey(hKey);
   End If
   SaveSetting = (nRet = ERROR_SUCCESS)
End Function

any ideas why I'm getting this error. My virtual disk space is at 1.5GB and I'm sure I have enough memory (1GB RAM), what other resources could be gone? I have nothing else running that uses a lot of resources.
0
Comment
Question by:guidway
9 Comments
 
LVL 5

Assisted Solution

by:dc197
dc197 earned 100 total points
ID: 9674489
I use the String and Long versions:


 Public Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
   
 Public Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
   



Public Function PutRegKeyEx _
    ( _
        ByVal hKey As Long _
        , sValueName As String _
        , lType As Long _
        , vValue As Variant _
    ) As Long
    DoEvents
   
    Dim lValue As Long
    Dim sValue As String
    Select Case lType
    Case StringKey
        sValue = vValue & Chr$(0)
        PutRegKeyEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
    Case DoubleWord
        lValue = vValue
        PutRegKeyEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
    End Select
End Function

0
 
LVL 12

Author Comment

by:guidway
ID: 9674672
hi dc197,

thanks for the response, I tried that just now and got the same error. I have successfully been able to read from the registry (manually and programmatically) and I can write values to it manually using regedit but not programmatically. Anytime I try to use RegSetValueEx (or RegSetValueExString) I get the same error code... I'm on a Win2k SP3 O.S. using VB6SP5 so I'm doubtful it is a bug. It's frustrating that I can't get more info about what is causing the error. It is too generic... thanks again

guid
0
 
LVL 12

Author Comment

by:guidway
ID: 9674697
>>so I'm doubtful it is a bug<<

let me clarify that statement. I mean I doubt it is a bug in Microsoft's code base since I have the latest service pack. I didn't mean I was doubtful it was a bug on my part. In fact, I'm about 95% sure it is since I seem to be the only one on the web having this error. ;)
0
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 100 total points
ID: 9675507
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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

Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Save a string to the key
    RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
    'close the key
    RegCloseKey Ret
End Sub

Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Set the key's value
    RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
    'close the key
    RegCloseKey Ret
End Sub

Private Sub Command1_Click()
    Dim strString As String
    'Ask for a value
    strString = InputBox("Please enter a value between 0 and 255 to be saved as a binary value in the registry.", App.Title)
    If strString = "" Or Val(strString) > 255 Or Val(strString) < 0 Then
        MsgBox "Invalid value entered ...", vbExclamation + vbOKOnly, App.Title
        Exit Sub
    End If
    'Save the value to the registry
    SaveStringLong HKEY_CURRENT_USER, "keyitem", "BinaryValue", CByte(strString)
End Sub


~ fantasy ~
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Accepted Solution

by:
EDDYKT earned 300 total points
ID: 9678325
0
 
LVL 12

Author Comment

by:guidway
ID: 9679031
I've tried it everyway so far and everytime it gets to that line it gives the same error. I've even rebooted the computer to make sure it wasn't too many resources. I'm going to try increasing the size of the registry limit in win2k and see if that helps.
0
 
LVL 12

Author Comment

by:guidway
ID: 9679038
that had no effect
0
 
LVL 12

Author Comment

by:guidway
ID: 9679564
just tried the code for EDDYKT again and then it started working. I guess it may have been a copy error when I tried copying the code over. Anyway, I appreciate everyone's effort.

300 pts to EDDYKT
100 pts for fantasy1001
100 pts for dc197

thanks again
guid
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9683177
Thanks,
It is cool to know you have solve the problem.

~ fantasy ~
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now