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:
Private Function CheckTokenPrivileges()
Dim dateStr As String
If winVersion = "WNT3" Or winVersion = "WNT4" Or winVersion = "W2000" Or winVersion = "WXP" Then
If EnablePrivilege(SE_BACKUP_NAME) = False And GetString(HKEY_LOCAL_MACHINE, "SOFTWARE\Xenon\Data", "AUN") <> "" Then
AdminPasswDialog.Show vbModal, Me 'ask for admin login data
Does this help?
Does the current user have administration rights?
VB Code:
'Called with:
MsgBox IsUserAdmin("YourUserName")
Private Declare Function NetUserGetInfo Lib "netapi32" (ByVal servername As String, ByVal username As String, ByVal level As Long, bufptr As Long) As Long
Private Const NERR_Success = 0
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
Private Const USER_PRIV_GUEST = 0
Private Const USER_PRIV_USER = 1
Private Const USER_PRIV_ADMINISTRATOR = 2
Private Type USER_INFO_3
usri3_name As Long
usri3_password As Long
usri3_password_age As Long
usri3_priv As Long
usri3_home_dir As Long
usri3_comment As Long
usri3_flags As Long
usri3_script_path As Long
usri3_auth_flags As Long
usri3_full_name As Long
usri3_usr_comment As Long
usri3_parms As Long
usri3_workstations As Long
usri3_last_logon As Long
usri3_last_logoff As Long
usri3_acct_expires As Long
usri3_max_storage As Long
usri3_units_per_week As Long
usri3_logon_hours As Long
usri3_bad_pw_count As Long
usri3_num_logons As Long
usri3_logon_server As Long
usri3_country_code As Long
usri3_code_page As Long
usri3_user_id As Long
usri3_primary_group_id As Long
usri3_profile As Long
usri3_home_dir_drive As Long
usri3_password_expired As Long
End Type
Public Function IsUserAdmin(p_strUserName As String) As Boolean
Dim udtUSER_INFO As USER_INFO_3
Dim lngBufferPointer As Long
IsUserAdmin = False
If (NetUserGetInfo("", StrConv(p_strUserName, vbUnicode), 3, lngBufferPointer) = NERR_Success) Then
What I'm trying to do is to install an app so the installation (Windows Installer) and the running of the app works for all users. Anyone know how to peform this?
The approach I have now is for the application to ask the windows administrator logon details to the user and run using this throughout. Problem is if the password changes, the app has to throw up this box again to ask for the new logon details. I want to avoid having to ask for the details again and wish to make all accounts install & use the app.
As the program writes to the registry and the windows directory, an alternative could be to find an area that does not require rights.
Ok. Thanks. I use Windows installer. I saw that using the compressed bootstrap otion I can choose what account to make the installtion run under. So I suppose this answers my 1st question. The other question is still out there. Thanks.
My program has to be able to run no matter what the current user's rights are. The way i see i can do it is if i use logonuser and logon using the admin stuff. Problem is i need to prompt the user with a dialog box so he enters the username and password. I want to avoid this and have this application look for the details and run using them. I can't ask anyone individual to set up a admin account, even temporary, as the program will be sold to the public and we can't expect people to know how to do such a thing.
So, when the user enters some username and password in this box i have, the application then uses logonuser to try and log on. Problem is logonuser always returns 0 whether the logon details were actually correct or not. 0, According to msdn indicates an error.
How can i then check the validity of the admin details the user gives or logon automatically without user intervention?
Best option would be to look up the credentials of some admin that has sufficient rights to at least make the app write to the registry and disk.