0

Ok so I have a batch file named tc1.bat that has the following line

start java -jar \\master\TestClient\dist\TestClient.jar

I want to be able to run tc1.bat (manually by double clicking on it, which starts TestClient.jar and I want TestClient to be able to put that bat file into the RunOnce key in the windows registry. So basically a program that can put itself into the computer's startup routine for the next startup.

I need to be able to get the relative/current path when the app runs because I won't always know where the batch file gets run from. Below is some pseudo-code

public static main {
    getCurrentDirectory();
    addToRegistry("HKLM/Software/microsoft/windows/currentversion/runonce" 
        "patchToCurrentDirectory\tc1.bat");
}

So the end result is that I run the batch file, lets say from the desktop, it will run the program that will insert into the runOnce to run the bat file that is on the desktop that originally ran the program.

To shed some light on what I'm trying to do, I have a program that will be able to shutdown or restart the PC. I want to be able to have an option to say "restart this PC but run the program after the PC restarts".

*Alternatively, If I could actually just write the patch directly to the JAR file in the runOnce without having to use a batch file, that would be even better. I tried putting start java -jar etc... into the runOnce but it doesnt work.

Richard Chase
  • 407
  • 5
  • 21
  • Slightly different approach here... why not have the batch file examine the exit code from your Java app and let the batch file update the registry, if needed, based on that exit code (using `regedit`)? That way you keep all the Windows-specific goo in the Windows-specific batch file. And bonus: the batch file can determine its own/current directory (e.g. [`%~dp0`](http://stackoverflow.com/questions/17063947/get-current-batchfile-directory)). – Rusty Shackleford Jul 21 '15 at 03:52
  • Note that using `start` will not wait for `java` to exit. So you may need a second batch file that runs `java` and waits for it to exit (i.e. what you have above minus `start`). The second batch file would be `start`ed from the first. – Rusty Shackleford Jul 21 '15 at 04:01
  • That's not a bad idea Equality. What I ended up doing is creating a file and then getting it's absolutepath. That would tell me the working dir which was win/sys32. I found out that when running from runOnce, I cant write files to that dir so I ended up changing my approach to writing to %temp% and all is well. – Richard Chase Jul 26 '15 at 21:54

0 Answers0