Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Running .JAR file issue.

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Running .JAR file issue.

    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!


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Running .JAR file issue.

    You shouldn't be killing the process, just wait for it to terminate normally.

    p = Runtime.getRuntime().exec("command");
    p.waitFor(); // waits until process p terminates

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Running .JAR file issue.

    But it never terminate, and even if I dont add that in the code, it still dont run

    --- Update ---

    Still don't run in windows xp

  4. #4
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Running .JAR file issue.

    So nobody has an Idea, why is this not working on windows xp?

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Running .JAR file issue.

    I don't have an XP machine to test with, but I did find this post over at stack exchange where they were able to read/write to the Windows registry without having to use JNI, reg processes, etc. It may solve your problem by simply avoiding it to begin with.

  6. #6
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Running .JAR file issue.

    My problem is not reading or modifying the registry. (Thats what I think)

    Because it actually create the registry, that I want and read from it, bot it just don't continue. As you can see in my code the first "while" is not executing which will open a dialog box and ask for some info, but that does not happen in windows xp.

    --- Update ---

    And I downloaded Eclipse in a windows xp machine to test if it was a 64x 32x problem and copying and pasting the code in the console, does the same thing. Thanks.

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Running .JAR file issue.

    What I meant was the solution presented in that post doesn't use external processes at all. No need to worry about any processes terminating correctly or having to parse piped output, you just get your results and get on with your program.

  8. #8
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Running .JAR file issue.

    Okay, thanks.

    I'll try that.

    --- Update ---

    Now, I'm using the code from the link that you posted.

    Let's say that you run this code:

    String value = WinRegistry.readString (
    				WinRegistry.HKEY_CURRENT_USER,                             //HKEY
    				"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Korbel\\" + server,           //Key
    				"Certified");                                              //ValueName
     
    		System.out.println("Value = " + value);

    In your computer since that string does not exist, the program is going to print this out:

    Value = null

    Now, I want to create that string, if is not in your system.

    I'm trying to user this:

    if(value.contains("null"))
     
    			{
    ...
    }

    But it does not do anything, meaning that the null that is printed out at the beginning is not a string, or something else that i yet don't understand.

    What could the problem be? And how can I solve this? Thanks.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Running .JAR file issue.

    What variable is used to print this:
    Value = null
    To test that if the variable used to create the above printout is null compare it to null, not the String "null"
    if(value == null)

    If value was null then the following would give a NPE:
    if(value.contains("null"))
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Running .JAR file issue.

    What do you mean by NPE?

  11. #11
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Running .JAR file issue.

    NPE = NullPointerException

  12. #12
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Running .JAR file issue.

    I solved the problem by doing this:

    if((value = Error) != null)
    		{
    ...
     
    }

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Running .JAR file issue.

    Why not just test the value of the Error variable directly?
    if(Error != null)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Issue with running DataGimmick program
    By Bentino in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 20th, 2012, 04:42 AM
  2. Problem running .jar in Windows 7
    By SpiceProgrammer in forum Java Theory & Questions
    Replies: 3
    Last Post: December 21st, 2011, 01:28 AM
  3. Running an Applet With JAR file
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 20th, 2011, 07:10 AM
  4. [SOLVED] jar file Built(clean and build) perfectly, but not running as jar
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: July 11th, 2011, 11:41 AM
  5. Authentication system for running/downloading a .jar
    By KiwiProg in forum Java Theory & Questions
    Replies: 1
    Last Post: January 3rd, 2011, 01:29 AM