View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
urkec urkec is offline
external usenet poster
 
Posts: 131
Default Is there anyway to retrieve Registry Values from VBA???

"FunkySquid" wrote:

Well I've searched for my full name in the registry and it shows up in
the following string:

HKEY_CURRENT_USER\Software\Inifiles\User Profile.ini\User Profile

"UserName" = "MyFullName"

Is there a way of retrieving this by using VBA or is there another way
to retrieve MyFullName from my computer?



If you need full name of a user account, you can use WinNT provider:

Sub WinNTtest()

Set objNetwork = CreateObject _
("Wscript.Network")

strComputer = objNetwork.ComputerName
'strUser = objNetwork.UserName
strUser = "baba"

Set objUser = GetObject("WinNT://" & _
strComputer & "/" & strUser & ", user")

Debug.Print objUser.get("FullName")

End Sub

If you want full name of a currently logged on user you can use strUser =
objNetwork.UserName to get user's name.

You can also use WMI service:

Sub WMItest()

strUser = "baba"

Set objWMIService = GetObject _
("WinMgmts:root\cimv2")

Set colUsers = objWMIService.ExecQuery _
("Select * From Win32_UserAccount " & _
"Where Name='" & strUser & "'")

For Each objUser In colUsers
Debug.Print objUser.FullName
Next

End Sub


If the user is in a domain you would use LDAP, but I don't have much
experience with that.

--
urkec