This is my code:
//By José D. Hernández, 2013. import java.io.*; import javax.swing.*; import java.awt.*; public class PasswordDialog { public static void main(String[] args) throws IOException { String line, usern, passw, servdns = "108.168.227.11", check1, check2, server = "TERMSVR5", rdp = "LaUnion"; CharSequence look = "REG_SZ", Error = "0 match(es)"; Process p; Boolean stop = true, stop2 = true; Runtime runtime = Runtime.getRuntime(); p=Runtime.getRuntime().exec("reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server); p=Runtime.getRuntime().exec("taskkill /F /IM Reg.exe"); Process process = runtime.exec("reg query HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server + " /v Verified /t REG_SZ"); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); while ((line = br.readLine()) != null && stop) { if(line.contains(Error)) { JPanel userPanel = new JPanel(); userPanel.setLayout(new GridLayout(2,2)); JLabel usernameLbl = new JLabel("Username:"); JLabel passwordLbl = new JLabel("Password:"); JTextField username = new JTextField(); JTextField passwordFld = new JTextField(); userPanel.add(usernameLbl); userPanel.add(username); userPanel.add(passwordLbl); userPanel.add(passwordFld); int input = JOptionPane.showConfirmDialog(userPanel, userPanel, "Credentials:" ,JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (input == 0) { usern = username.getText(); passw = passwordFld.getText(); p=Runtime.getRuntime().exec("reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server + " /v Certified /t REG_SZ /d " + usern); p=Runtime.getRuntime().exec("reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server + " /v Starting /t REG_SZ /d " + passw); p=Runtime.getRuntime().exec("reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server + " /v Verified /t REG_SZ /d " + servdns); p=Runtime.getRuntime().exec("cmdkey /generic:TERMSRV/" + servdns + " /user: " + usern + " /pass: " + passw); p=Runtime.getRuntime().exec("mstsc.exe C:\\Windows\\System32\\drivers\\etc\\" + rdp + ".rdp"); } else { System.exit(0); } } else { stop = false; p=Runtime.getRuntime().exec("reg query HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server + " /v Certified"); BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); check1=reader.toString(); while ((check1 = reader.readLine()) != null && stop2) { if(check1.contains(look)) { String username = (check1.split(" ")[12]); p=Runtime.getRuntime().exec("reg query HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server + " /v Starting"); BufferedReader reader2=new BufferedReader(new InputStreamReader(p.getInputStream())); check2=reader2.toString(); stop2 = false; while ((check2 = reader2.readLine()) != null) { if(check2.contains(look)) { String password = (check2.split(" ")[12]); p=Runtime.getRuntime().exec("cmdkey /generic:TERMSRV/" + servdns + " /user: " + username + " /pass: " + password); p=Runtime.getRuntime().exec("mstsc.exe C:\\Windows\\System32\\drivers\\etc\\" + rdp + ".rdp"); } } } } stop = true; } } System.exit(0); } }
Is working just fine, it does what I want, perfect to me, when I run it in Eclipse and also when I export the program to a runable .JAR file it runs! I have Windows 7 Enterprise Edition 64x but when I try to run the same .JAR file in Windows XP Professional it get stuck...
My code create a registry key in the windows registry and the it goes on, in windows xp it only create that key, which is this part:
p=Runtime.getRuntime().exec("reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server);
I tough that maybe because I'm killing the reg process after that execution, it could be the problem, but I deleted it and it was still not working.
HELP!