1

I am writing a java program to print password in log-in page of windows 10 (to get automatically login when I do some action)
I try to use printwriter to do that .
I managed to print the text inside a text file .
but I want to print the text in password's text box of login page in windows 10

any idea please ..

Thanks

import java.io.*; 

class Hasan{ 
    public static void main(String[] args)  
        try {  
            PrintWriter writer=PrintWriter(System.out);  
            writer.write("mypassword");   
        } 
        catch (Exception e) { 
            System.out.println(e); 
        } 
    } 
} 

when I used System.out I just could printed text in console screen

Hasan_Naser
  • 204
  • 3
  • 13

2 Answers2

1

That's not going to work. While you can use for example java.awt.Robot to fill out things when the desktop is unlocked and your program is running, the login screen is a whole different thing. For security reasons you won't be able to get any custom programs to do the logging in for you. At least not with Java, and not without root access.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • **Thank you Kayaman** , after convert it to _.exe_ I managed to make code run automatically in login page using _Task Scheduler_ . firstly I used `java.awt.Robot` to do that but it just could moved the pointer of mouse in login page and could not make keypress work to print password with out I know the reason . for that I try to use `PrintWriter` – Hasan_Naser Sep 09 '19 at 07:57
1

PrintWriter is designed to print a sequence of bytes on a stream. UI widgets, like textboxes, have no stream support.

If you want to target a textbox owned by a process in the same security context as yours, you have to identify the process owning the window and use the OS primitives (SendMessage, PostMessage, ...) to enter your text.

Processes outside your security context are unreachable and at least require that your process is elevated.

Note that certain textboxes may refuse certain types of message when they are working in ''password'' mode, i.e. masking the input. This is to prevent applications from stealing the context of the textbox.

A more wise solution, would be to let the user set the focus on the UI control they wants, and then let them pressing a keyboard hotkey to trigger your program. Your program can then use use SendInput to send the keyboard characters one by one as if the user was typing.

Both the solutions are feasable in native language (C, C++) or PInvoked (C#), for java, have a look at Sending a Keyboard Input with Java JNA and SendInput().

Yennefer
  • 5,704
  • 7
  • 31
  • 44