locked
How to logon the UI of the workstation RRS feed

  • Question

  • Using advapi32 user logon in java

    //Login Successful but not UI login
    USER_INFO_1 userInfo = new USER_INFO_1();
    userInfo.usri1_name = new WString("Kai");
    userInfo.usri1_password = new WString("i930421015717c");
    userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
    Date d = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ssSSS");

    HANDLEByReference phUser = new HANDLEByReference();
    HANDLEByReference dupUser = new HANDLEByReference();

    try {
    boolean a = Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(), InetAddress.getLocalHost().getHostName(), userInfo.usri1_password.toString(), Kernel32.INSTANCE.LOGON32_LOGON_NEW_CREDENTIALS, Kernel32.INSTANCE.LOGON32_PROVIDER_DEFAULT, phUser);
    Advapi32.INSTANCE.ImpersonateLoggedOnUser(phUser.getValue());

    System.out.println("After Logon User Method \nCheck login \ntime :" + sdf.format(d.getTime()) + " - " + a  + " " + InetAddress.getLocalHost().getHostName());

    Advapi32.INSTANCE.DuplicateToken(phUser.getValue(), userInfo.usri1_priv, dupUser);

    if (a == true){
    Advapi32.INSTANCE.ImpersonateSelf(sessionId);
    System.out.println("Windows Update : " +User32.INSTANCE.UpdateWindow(hWnd));




    //User32.INSTANCE.RedrawWindow(arg0, arg1, arg2, arg3)
    //Update or redraw the windows using user32.Instance
    }
    } catch (LastErrorException | UnknownHostException e) {
    // TODO Auto-generated catch block
    e.getMessage();
    Kernel32.INSTANCE.GetLastError();
    }finally{
    if(phUser.getValue() != WinBase.INVALID_HANDLE_VALUE){
    Kernel32.INSTANCE.CloseHandle(phUser.getValue());
    }
    }

    Netapi32.INSTANCE.NetUserDel(null, "Kai");

    Thursday, October 8, 2015 10:37 AM