ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Read Registry Keys (and possibly write) (https://www.excelbanter.com/excel-programming/358364-read-registry-keys-possibly-write.html)

Mike Iacovou

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

Jim Cone

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"
wrote in message
...
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

Steve Yandl

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\Curr entVersion\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=imper sonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\excel.exe"
strValueName = ""
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValu e
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" wrote in message
...
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




Ron de Bruin

Read Registry Keys (and possibly write)
 
See
http://www.rondebruin.nl/register.htm

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


"Mike Iacovou" wrote in message ...
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




Mike Iacovou

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.



All times are GMT +1. The time now is 10:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com