[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SaveSetting position

Posted on 2000-05-12
9
Medium Priority
?
331 Views
Last Modified: 2010-05-02
When I use the SaveSetting / GetSetting commands in VB to write / retrieve registry values, it is stored always in the branch "VB and VBA Program Settings" under "Software" under "HKEY_CURRENT_USER".

The question is: how can I make the values to be forced to be stored in other place (i.e. under "Software" under "HKEY_LOCAL_MACHINE")?
0
Comment
Question by:BETTY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 2804828
u need to use the registry API.
This is not mine but i was provided this link when i asked the same q.
http://homepage.eircom.net/~carafa/VBSamples/VBAll/shellexecute.zip
0
 
LVL 13

Expert Comment

by:crazyman
ID: 2804836
0
 
LVL 9

Accepted Solution

by:
GivenRandy earned 200 total points
ID: 2804886
Use these functions:

-----
Public Function ReadRegistry(ByVal Key As String, ByVal Name As String, ByVal DefaultValue) As String
    Dim KeyHandle As Long
    Dim Result As Long
    Dim LType As Long
    Dim Data As String
    Dim DataLen As Long
     
    ReadRegistry = DefaultValue
    Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Key, 0, KEY_READ, KeyHandle)
    If (Result = ERROR_SUCCESS) Then
        DataLen = 500
        Data = String$(DataLen, 0)
        Result = RegQueryValueEx(KeyHandle, Name, 0, LType, ByVal Data, DataLen)
        If (Result = ERROR_SUCCESS) Then
            ReadRegistry = Left$(Data, DataLen - 1)
        End If
    End If
    Call RegCloseKey(KeyHandle)
End Function

Public Sub WriteRegistry(ByVal Section As String, ByVal Key As String, ByVal ValType As Integer, ByVal Value As Variant)
    Dim lResult As Long
    Dim lKeyValue As Long
    Dim InLen As Long
    Dim lNewVal As Long
    Dim sNewVal As String
     
    On Error Resume Next
    lResult = RegCreateKey(HKEY_LOCAL_MACHINE, Section, lKeyValue)
    If ValType = ValDWord Then
       lNewVal = CLng(Value)
       InLen = 4
       lResult = RegSetValueExLong(HKEY_LOCAL_MACHINE, Key, 0&, ValType, lNewVal, InLen)
    Else
       If ValType = ValString Then Value = Value & Chr(0)
       sNewVal = Value
       InLen = Len(sNewVal)
       lResult = RegSetValueExString(lKeyValue, Key, 0&, 1&, sNewVal, InLen)
    End If
    lResult = RegFlushKey(lKeyValue)
    lResult = RegCloseKey(lKeyValue)
    On Error GoTo 0
End Sub
-----

You'll need this information in a module:

-----
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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
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
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
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
-----
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Vbmaster
ID: 2805157
I use a class that works as a wrapper around the registry API's, you can get it from..

http://www.cyd.liu.se/~freqv416/clsRegistry.cls
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2805190
if you go to project -> references and add an reference to the "windows scripting runtime you can implement something like this:

Dim wshShell As New IWshShell_Class
wshShell.RegWrite _
"HKEY_CURRENT_USER\" _
      & "Software\" _
      & "Microsoft\" _
      & "Internet Explorer\" _
      & "Main\" _
      & "Start Page" _
      , strMyRegistryValue

wshShell.Regwrite will overwrite the value if the key is found or add it to the registry if it is not

<code compliments of another expert at this site...wsh2>


     
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2854670
Did we help any?
0
 
LVL 1

Author Comment

by:BETTY
ID: 2856402
I'm sorry for the delay.
I'm changing my job place and I have been very very busy. I think in a week I will be able to evaluate and compare your comments.
Thanks for the patience...
0
 
LVL 1

Author Comment

by:BETTY
ID: 2950742
Hi after this long delay! I'm very sorry.

Well, and the winner is... all of you, for trying to help me.
The points go to GivenRandy, and that's why: all the options finally worked in a simple testing, with a maximum effort of retouching a couple of lines, but GivenRandy was a "direct" answer, without having to search for any other place (Anyway the links were interesting, CrazyMan). And I wasn't able to locate the Windows Scripting Runtime under References nor under Components. Finally, GivenRandy's option does not use classes, where I am a complete newbie.

Thanks to all, and sorry one more time for the delay.
0
 
LVL 1

Author Comment

by:BETTY
ID: 2950762
Comment accepted as answer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 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