From: Brandon on
I am working on a script that runs under a custom installation
utility, which is running as a service. To get the current user name
the script executes this command:

str_Acct_Name_Val = "HKCU\Software\Microsoft\Windows\CurrentVersion
\Explorer\Logon User Name"
str_Acct_Name = RegRead(str_Acct_Name_Val)

When I run the script from the command prompt, it can read that value
just fine (under an administrator account). When the value is
attempted to be read with service/local system privileges, the read
fails.

What is the problem here?
From: Brandon on
Some additional information. When running as a service calling the
current user name returns "SYSTEM" and my guess is that HKCU doesn't
"exist" under the view of the SYSTEM, since there is technically no
current user. There is a user logged in at the time, but not in the
scope of the running script. Maybe there is somewhere in HKLM I could
find the currently logged on user?
From: LikeToCode on
So why not query the owner of a specific process like "explorer.exe".

Option Explicit
Dim objWMIService, colProcessList, objProcess, colProperties
Dim strUserDomain, strUserName
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProcess in colProcessList
If objProcess.name = "explorer.exe" Then
colProperties = objProcess.GetOwner(strUserName,strUserDomain)
Wscript.Echo "The current User is: " & strUserDomain & "\" &
strUserName & "."
End If
Next