+ Reply to Thread
Results 1 to 5 of 5

Read Registry Keys (and possibly write)

  1. #1
    Mike Iacovou
    Guest

    Read Registry Keys (and possibly write)

    Hi all.

    I've had a quick search & "google" for vba code to read (and maybe write) to
    registry keys. I know there is a GetSetting / SaveSetting function for
    specific keys, but I'm hoping to be able to read other registry key
    information (mainly application paths). I suppose this can be achieved by a
    COM call - but would appreciate any tutorials / guides / info.
    For the sake of argument, reading the "path" of "excel.exe" in current apps
    for any demo code.
    TIA

  2. #2
    Jim Cone
    Guest

    Re: Read Registry Keys (and possibly write)

    Here is a start...
    http://support.microsoft.com/kb/145679/en-us#top
    "How To Use the Registry API to Save and Retrieve Setting"

    Jim Cone
    San Francisco, USA
    http://www.realezsites.com/bus/primitivesoftware



    "Mike Iacovou" <[email protected]>
    wrote in message
    news:[email protected]...
    Hi all.
    I've had a quick search & "google" for vba code to read (and maybe write) to
    registry keys. I know there is a GetSetting / SaveSetting function for
    specific keys, but I'm hoping to be able to read other registry key
    information (mainly application paths). I suppose this can be achieved by a
    COM call - but would appreciate any tutorials / guides / info.
    For the sake of argument, reading the "path" of "excel.exe" in current apps
    for any demo code.
    TIA

  3. #3
    Steve Yandl
    Guest

    Re: Read Registry Keys (and possibly write)

    Here are two approaches other than using Windows API functions.

    For the examples, these would return the default value under
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
    Paths\excel.exe

    First,

    Dim wsh
    strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
    & "CurrentVersion\App Paths\excel.exe\"
    Set wsh = CreateObject("WScript.Shell")
    MsgBox wsh.RegRead(strKeyPath)

    of if you're on WinMe/XP/2k or beyond (WMI is installed on the PC), you
    could use

    Const HKEY_LOCAL_MACHINE = &H80000002
    strComputer = "."
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\App
    Paths\excel.exe"
    strValueName = ""
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
    MsgBox strValue


    Using WMI gives you more flexibility when reading multiple subkeys or values
    but the "WScript.Shell" option would be available on more machines. You can
    also write new values or amend existing ones.

    Steve

    "Mike Iacovou" <[email protected]> wrote in message
    news:[email protected]...
    > Hi all.
    >
    > I've had a quick search & "google" for vba code to read (and maybe write)
    > to
    > registry keys. I know there is a GetSetting / SaveSetting function for
    > specific keys, but I'm hoping to be able to read other registry key
    > information (mainly application paths). I suppose this can be achieved by
    > a
    > COM call - but would appreciate any tutorials / guides / info.
    > For the sake of argument, reading the "path" of "excel.exe" in current
    > apps
    > for any demo code.
    > TIA




  4. #4
    Ron de Bruin
    Guest

    Re: Read Registry Keys (and possibly write)

    See
    http://www.rondebruin.nl/register.htm

    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "Mike Iacovou" <[email protected]> wrote in message news:[email protected]...
    > Hi all.
    >
    > I've had a quick search & "google" for vba code to read (and maybe write) to
    > registry keys. I know there is a GetSetting / SaveSetting function for
    > specific keys, but I'm hoping to be able to read other registry key
    > information (mainly application paths). I suppose this can be achieved by a
    > COM call - but would appreciate any tutorials / guides / info.
    > For the sake of argument, reading the "path" of "excel.exe" in current apps
    > for any demo code.
    > TIA




  5. #5
    Mike Iacovou
    Guest

    Re: Read Registry Keys (and possibly write)

    @Jim & Steve - many thanks.
    @Ron - thanks as ever. The WSH method is simple - but I am not sure if this
    is present on Win95/NT systems - and the vbapp is running on these
    I opted to modify the API call example you referenced - and it works nicely
    ( i assumed that this will be compatible across the whole windows family)
    thanks again to all.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1