Results 1 to 10 of 10
- 12-20-2008, 04:43 AM #1
[SOLVED] Making a program to open a file (.exe)
Ok i have been trying to create a java program that would open an executable file when entered a password. (I am making the java program an executable using exe4j)
This is my code so far: (it does not work because you can't do: file.open())
import java.util.Scanner;
import java.io.*;
public class Passcode
{
public static void main (String[]args)
{
Scanner keyB = new Scanner (System.in);
String ans = "password";
String pass;
System.out.println("Enter a password: ");
pass = keyB.nextLine();
if (pass.equals(ans))
{
File file = new File("C:/Program Files/WarCraft3/WC3.EXE");
file.open();
}
else
System.out.println("Invalid Password");
}
}
Does anybody have any suggestions?
Please reply.-- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
-- 2.66 Ghz Pentium Geforce NVidia 440 64mb
- 12-20-2008, 06:16 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
Please read Runtime Class doc
- 12-20-2008, 12:35 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 43
- Rep Power
- 0
Hi Linux,
Hope this helps:
The easiest way for you to run exe at run time (i.e., you'll have to make
sure that it exists) is to use the Java's built-in Process.
The general way is
Process process = Runtime.getRuntime().exec(as, es, dir);
where as is the String [] of the command (full-path) and its arguments,
es is the String [] of the environments (more suitable in unix)
dir is a File specifying the working directory.
Thus, if the file is MyExe.exe that resides in c:\mydir, you'll do
as[0] = "c:\mydir\MyExe.exe";
es = null;
dir=new File("c:\mydir");
.... exec(as,es,dir);
- 12-20-2008, 12:37 PM #4
Member
- Join Date
- Sep 2008
- Posts
- 43
- Rep Power
- 0
as[0] = "c:\Program Files\WarCraft3\WC3.EXE";
es = null;
dir=new File("c:\Program Files\WarCraft3\");
Also, remember to use "\" instead of "/" for directory's ;)
- 12-21-2008, 05:56 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 12-22-2008, 05:17 AM #6
Thanks for all the help!:D
-- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
-- 2.66 Ghz Pentium Geforce NVidia 440 64mb
- 12-22-2008, 10:51 PM #7
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
so what was the final code that works?
and were do you find "Runtime Class doc" so you can read it?
I did a forum search but wasted my time
I notice you might have to go
File file = new File("C:\\Program Files\\WarCraft3\\WC3.EXE");
- 12-22-2008, 11:37 PM #8
For some reason I can not post links, but just google runtime class java, it should be the first thing to come up.
-- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
-- 2.66 Ghz Pentium Geforce NVidia 440 64mb
- 12-23-2008, 12:09 AM #9
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
So what does the code look like? that will get closer to your "post count must be 20 or greater"
- 12-23-2008, 12:27 AM #10
here's the code: 9here i use the program to open audacity with password
import java.util.Scanner;
import java.io.File;
public class open
{
public static void main (String[]args) throws Exception
{
Scanner keyB = new Scanner (System.in);
String ans = "hacker";
String trying;
System.out.println("****************************** **********");
System.out.println("* Anti-deleter *");
System.out.println("* By:**************** *");
System.out.println("****************************** **********");
System.out.print("\nPlease enter a password: ");
trying = keyB.nextLine();
if (trying.equals(ans))
{
System.out.println("Correct password!");
Process p = Runtime.getRuntime().exec("C:/Program Files/Audacity/audacity.EXE");
}
else
System.out.println("Invalid password!");
}
}-- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
-- 2.66 Ghz Pentium Geforce NVidia 440 64mb
Similar Threads
-
Help Making a program not crash
By Lifeis2evil in forum New To JavaReplies: 2Last Post: 12-10-2008, 03:10 AM -
Need help with Java classes for making a program.
By TheDarkReverend in forum Advanced JavaReplies: 2Last Post: 11-28-2008, 04:50 AM -
[SOLVED] Making JAVA Program excutable
By kirly in forum Advanced JavaReplies: 10Last Post: 10-07-2008, 03:57 AM -
To open an image file such as Jpeg file using JAva Program
By itmani2020 in forum Advanced JavaReplies: 10Last Post: 07-11-2008, 09:57 AM -
code for making a java swing program a demo verson
By fakhruddin in forum AWT / SwingReplies: 1Last Post: 11-27-2007, 08:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks