I have the following code:
//By José D. Hernández, 2013. import java.io.*; import java.util.Scanner; public class ugh { public static void main(String args[]) throws IOException, InterruptedException { String line, usern, passw; CharSequence look = "127.0.0.1"; Scanner scan = new Scanner (System.in); System.out.print("Username: "); usern = scan.next(); System.out.print ("Password: "); passw = scan.next( ); Process p=Runtime.getRuntime().exec("cmdkey /list"); p.waitFor(); BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); line=reader.toString(); while(line!=null) { if(line.contains(look)) p=Runtime.getRuntime().exec("mstsc.exe C:\\test.rdp"); else p=Runtime.getRuntime().exec("cmdkey /generic:TERMSRV/127.0.0.1 /user: " + usern + " /pass: " + passw); line=reader.readLine(); } } }
I want this Java Program to ask for a "username" and a "password" only the first time I run it and then store it some how and never deletes it (This is where I'm honestly lost).
The purpose of this Java Program so you can understand it better is to execute the "cmdkey /list" command (which will list all the credentials saved in a local computer) and then read the output of the command and check if certain credentials are saved or not; If they are, my program will just run an .RDP file but if they are not, my program is going to add them, since I provided them first time.
Then every time the client open this app it wont ask for the user input, and it will just simply check if the credentials are in the local machine, go on or add them again. (Since we are having some difficulties with windows storing some credentials.)
I hope you guys understand and can help me with this, by the way I'm just a beginner.