Computer Name

I have a LAN based database app where users on 1/2 dozen computers edit a central database…
What I need to add is the ability to keep track of WHO altered the database (records are already timestamped)
In addition to the user name… I need the name of the computer (same user can log in on different machines)

to get the WHO … I am using this

  #If TargetMacOS Then
    
    Try
      Declare Function NSFullUserName Lib "Cocoa"  As CFStringRef
      current_user=NSFullUserName
    Catch
    End Try
    
  #ElseIf TargetWin32
    
    Dim custregitem As RegistryItem
    Try
      custRegItem = New RegistryItem("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion")
      current_user=custregitem.value("RegisteredOwner").StringValue
    Catch
    End Try
    
  #EndIf
  
  msgbox "You are "+current_user

which only gives me the REGISTERED user for Window… not the logged in user… Anyone know the correct change for THAT?

and what declares/registry values contain the NAME of the computer?

This is what I use. It’s from the Windows Functionality Suite:

[code]#if TargetWin32
Soft Declare Sub GetUserNameA Lib “AdvApi32” ( name as Ptr, ByRef size as Integer )
Soft Declare Sub GetUserNameW Lib “AdvApi32” ( name as Ptr, ByRef size as Integer )

dim mb as new MemoryBlock( 256 )
dim size as Integer = mb.Size()

if System.IsFunctionAvailable( "GetUserNameW", "AdvApi32" ) then
  GetUserNameW( mb, size )
  
  return mb.WString( 0 )
else
  GetUserNameA( mb, size )
  
  return mb.CString( 0 )
end if

#endif[/code]

and this, also from the WFS, will get the computer name:

[code] #if TargetWin32
Soft Declare Sub GetComputerNameA Lib “Kernel32” ( name as Ptr, ByRef size as Integer )
Soft Declare Sub GetComputerNameW Lib “Kernel32” ( name as Ptr, ByRef size as Integer )

dim mb as new MemoryBlock( 1024 )
dim size as Integer = mb.Size()

if System.IsFunctionAvailable( "GetComputerNameW", "Kernel32" ) then
  GetComputerNameW( mb, size )
  
  return mb.WString( 0 )
else
  GetComputerNameA( mb, size )
  
  return mb.CString( 0 )
end if

#endif[/code]

Thanks… here it is all wrapped up nice and pretty… and seems to work fine with OSX 10.8 and WIN7

  #If TargetMacOS Then
    
    Try
      Declare Function NSFullUserName Lib "Cocoa"  As CFStringRef
      Declare Function SCDynamicStoreCopyComputerName Lib "SystemConfiguration.framework" (store As Ptr, nameEncoding As Ptr) As CFStringRef
      current_user=NSFullUserName
      current_computer = SCDynamicStoreCopyComputerName(Nil, Nil)
    Catch
    End Try
    
  #ElseIf TargetWin32
    Declare Sub GetUserNameA Lib "AdvApi32" ( name As Ptr, ByRef size As Integer )
    Declare Sub GetUserNameW Lib "AdvApi32" ( name As Ptr, ByRef size As Integer )
    Declare Sub GetComputerNameA Lib "Kernel32" ( name As Ptr, ByRef size As Integer )
    Declare Sub GetComputerNameW Lib "Kernel32" ( name As Ptr, ByRef size As Integer )
    '
    Dim mb As New MemoryBlock(1024 )
    Dim size As Integer = mb.Size
    
    If System.IsFunctionAvailable( "GetUserNameW", "AdvApi32" ) Then
      GetUserNameW( mb, size )
      current_user=mb.WString( 0 )
    Else
      GetUserNameA( mb, size )
      current_user=mb.CString( 0 )
    End If
    If System.IsFunctionAvailable( "GetComputerNameW", "Kernel32" ) Then
      GetComputerNameW( mb, size )
      current_computer=mb.WString( 0 )
    Else
      GetComputerNameA( mb, size )
      current_computer=mb.CString( 0 )
    End If
  #EndIf
  
  MsgBox "You are "+current_user+" using "+current_computer