Read Windows Registry

BubbaBBQ

Board Regular
Joined
Jan 29, 2003
Messages
68
Okay, I've searched the forum, but no luck. Maybe I didn't hold my tongue right. :p Surely, this has been discussed and cussed.

Using a form, I need to read the value in the following registry location.

\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name

This will provide the logged in user name. Then the user clicks the STORE button, I need to store this value in the record with the rest of the fields the user typed in. I've got the date and time automagically storing. The book I'm referencing tells me that the GetSetting function will not read the Registry database in this branch.

Any suggestions?

Thanks much.

Bubba
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,

Reading a value from the registry requires Windows API functions and registry functions are quite involved. See here for an example.

If you just want to retrieve the Windows username then you could use the GetWindowsName function from below.

Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Function GetWindowsName() As String
    Dim lpBuff As String * 255
    Dim ret As Long, UserName As String

    ret = GetUserName(lpBuff, 255)
    GetWindowsName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
End Function
 
Upvote 0

Forum statistics

Threads
1,221,531
Messages
6,160,379
Members
451,642
Latest member
mirofa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top