This is probably because you are on x64 machine.
Check out this code.
Imports Microsoft.Win32
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim value As String
Dim localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64)
localKey = localKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI")
Dim value64 = localKey.GetValue("LastLoggedOnUser")
Dim localKey32 = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32)
localKey32 = localKey32.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI")
Dim value32 = localKey32.GetValue("LastLoggedOnUser")
If value64 = Nothing Then
value = value32
Else
value = value64
End If
MsgBox(value.ToString())
End Sub
End Class
EDIT post comments:
for a solution that access the remote machines registry check this:
Dim value As String
Dim strComputer As String = "Zack-PC"
Dim localKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, strComputer, RegistryView.Registry64)
localKey = localKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI")
Dim value64 = localKey.GetValue("LastLoggedOnUser")
Dim localKey32 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, strComputer, RegistryView.Registry32)
localKey32 = localKey32.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI")
Dim value32 = localKey32.GetValue("LastLoggedOnUser")
If value64 = Nothing Then
value = value32
Else
value = value64
End If
MsgBox(value.ToString)
Cheers