CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Posts
    2

    Unhappy LogonUser() failed

    HI,

    In my project, I need to logon programmatically on the local machine.

    I am using "LogonUser()" api. The calling process must have SE_TCB_NAME privilege enabled. I dont how to get that privilege.

    For that I have written following code.

    //Start
    if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hCurrentToken))
    printf("\n\nError Code for OpenProcessToken : %u",GetLastError());
    else
    printf("\nToken obtained");

    if(LookupPrivilegeValue(NULL, SE_TCB_NAME,
    &tkp1.Privileges[0].Luid))
    printf("\nLookup Privilege value TCB returned true");

    if(LookupPrivilegeValue(NULL, SE_CHANGE_NOTIFY_NAME,
    &tkp2.Privileges[0].Luid))
    printf("\nLookup Privilege value CHANGE returned true"); ;

    tkp1.PrivilegeCount = 1;
    tkp2.PrivilegeCount = 1;
    tkp1.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    tkp2.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    if(!AdjustTokenPrivileges(hCurrentToken, FALSE, &tkp1, 0,
    (PTOKEN_PRIVILEGES)NULL, 0))
    printf("\nCan't set privileges required in tkp1");

    dwErr = GetLastError();

    if((dwErr != ERROR_SUCCESS))
    printf("Error code for tkp1 : %u",dwErr);

    if(!AdjustTokenPrivileges(hCurrentToken, FALSE, &tkp2, 0,
    (PTOKEN_PRIVILEGES)NULL, 0))
    printf("\nCan't set privileges required in tkp2");

    dwErr = GetLastError();
    if(dwErr != ERROR_SUCCESS)
    printf("\nCan't set privileges required in tkp2");


    strcpy(pchUserName,"user1");
    strcpy(pchPasswd,"user1");
    strcpy(pchDomain,"MYDOMAIN");


    if(!LogonUser(pchUserName,pchDomain,pchPasswd,LOGON32_LOGON_INTERACTIVE
    ,LOGON32_PROVIDER_DEFAULT,&hToken))
    printf("\nLogon failed :\n\n ");

    //End

    Output :

    Token obtained
    Lookup Privilege value TCB returned true
    Lookup Privilege value CHANGE returned true

    Error code for tkp1 : 1300
    Logon failed :
    **************************************************

    Please help. How to set SE_TCB_NAME privilege and how to programmatically login on to the local computer.

  2. #2
    Join Date
    Mar 2002
    Posts
    350

    Re: LogonUser() failed

    Call GetLastError() after the call to AdjustTokenPrivileges(), if the return code is ERROR_NOT_ALL_ASSIGNED you need to add the privileges to your access token with LsaAddAccountRights() before enabling them

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured