1

I'm in a bit of a fix at the moment with an application I'm developing. Currently I am trying to get the program to run solely off of a USB flash drive. I want to achieve this because the computers at work don't have admin privileges to install Java. I have Java installed on my flash drive and I have my program on it as well. I would prefer to not have any CMD windows pop up because it looks really ugly. I would just like my GUI to appear but I'm running into the dumbest problem in the world. Relative paths. For some reason windows shortcuts will not allow relative paths and I can't find a way around it.

I have tried shortcuts, vbscript, and batch files. I really can't find a practical solution to this.

If anyone can offer any help, that'd be great, thanks!

EDIT: inb4 "Why do you need to do this? That's suspicious!, etc". I'm the IT guy and the program generates a nice little printer friendly table of system information in html.

zfollette
  • 475
  • 4
  • 15
  • Use an [HTA](https://msdn.microsoft.com/en-us/library/ms536496%28v=vs.85%29.aspx) instead of a Java application for this. – Ansgar Wiechers Jul 28 '15 at 17:51
  • Make a vbs file that runs your batch file [without showing the console window](http://stackoverflow.com/a/13142667/3959875). – wOxxOm Jul 28 '15 at 17:53
  • @bros05 I handle local IT. Fixing computers, monitoring CNC equipment, doing pricing for installing Wi-Fi for some examples. We have an off site IT guy that handles all server based operations i.e network backup, account, emails, spam filters. – zfollette Jul 28 '15 at 17:55
  • @Error why don't you talk to your other IT guy and tell him you need Java installed on the machines and tell him why... – brso05 Jul 28 '15 at 18:01
  • @brso05 Emailing him is like playing fetch with a dead dog. He'll get back to me sometime next week probably – zfollette Jul 28 '15 at 18:06
  • @Error Ah I see...maybe try what subtlepseudonym suggested I have used Launch4j before to create executables...it's a nice tool. – brso05 Jul 28 '15 at 18:08
  • You could use [Launch4j](http://launch4j.sourceforge.net/) with a bundled jre. A similar question has been answered [here](http://stackoverflow.com/questions/147181/how-can-i-convert-my-java-program-to-an-exe-file). – subtlepseudonym Jul 28 '15 at 17:53

1 Answers1

1

I finally got it! Due to @wOxxOm's link, I was able to make a command and work my way through the restrictions. Like you can't run cmd.exe /c ./dir/program.exe because cmd doesn't like the path to the program starting with ./ for some reason. It accepts "./dir/program.exe, but vbscript doesn't like the extra quotes. My final solution involved a combination of commands strung together with the && operator.

Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run("cmd.exe /c cd /java/64-bit/bin/ && java -jar ../../../resources/System_Information.jar"), 0, True

Just for reference, ../../../ was faster to type than another cd command.

Anyway, thanks for the help guys!

zfollette
  • 475
  • 4
  • 15