1. How can retrieve in code the administrator login details. I need this because people are going to use my program from within many user accounts and it will have to run using the administrator account using the LogonUser function.

2. How can I tell in code when I'm not running the windows administrator account? I saw this function for determining if I can write to the registry, but it does not always return false, and I want something more general.

VB Code:
  1. Private Function CheckTokenPrivileges()
  2.     Dim dateStr As String
  3.     If winVersion = "WNT3" Or winVersion = "WNT4" Or winVersion = "W2000" Or winVersion = "WXP" Then
  4.         If EnablePrivilege(SE_BACKUP_NAME) = False And GetString(HKEY_LOCAL_MACHINE, "SOFTWARE\Xenon\Data", "AUN") <> "" Then
  5.             AdminPasswDialog.Show vbModal, Me   'ask for admin login data
  6.         Else
  7.             Call SetNTPrivileges(True, GetString(HKEY_LOCAL_MACHINE, "SOFTWARE\Xenon\Data", "AUN"), _
  8.                 GetString(HKEY_LOCAL_MACHINE, "SOFTWARE\Xenon\Data", "APW"), _
  9.                 GetString(HKEY_LOCAL_MACHINE, "SOFTWARE\Xenon\Data", "ADM"))
  10.         End If
  11.     End If
  12. End Function
  13. Private Function EnablePrivilege(seName As String) As Boolean   'used to see what token privileges user has. It can't had any new ones though
  14.  
  15.     Dim p_lngRtn As Long
  16.     Dim p_lngToken As Long
  17.     Dim p_lngBufferLen As Long
  18.     Dim p_typLUID As LUID
  19.     Dim p_typTokenPriv As TOKEN_PRIVILEGES
  20.     Dim p_typPrevTokenPriv As TOKEN_PRIVILEGES
  21.     p_lngRtn = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, p_lngToken)
  22.     If p_lngRtn = 0 Then
  23.         Exit Function ' Failed
  24.     ElseIf Err.LastDllError <> 0 Then
  25.         Exit Function ' Failed
  26.     End If
  27.     p_lngRtn = LookupPrivilegeValue(0&, seName, p_typLUID)  'Used to look up privileges LUID.
  28.     If p_lngRtn = 0 Then
  29.         Exit Function ' Failed
  30.     End If
  31.     ' Set it up to adjust the program's security privilege.
  32.     p_typTokenPriv.PrivilegeCount = 1
  33.     p_typTokenPriv.Privileges.Attributes = SE_PRIVILEGE_ENABLED
  34.     p_typTokenPriv.Privileges.pLuid = p_typLUID
  35.     EnablePrivilege = (AdjustTokenPrivileges(p_lngToken, False, p_typTokenPriv, Len(p_typPrevTokenPriv), p_typPrevTokenPriv, p_lngBufferLen) <> 0)
  36. End Function

Many thanks to all.