0

I made a program in java that changes your windows wallpaper at a certain time of the day, this runs the UI and a thread in the background that checks if the wp should be changed or not.

I'm trying to figure out a way to keep track of that background thread and close it using a .bat file.

I run the program like this:

start javaw -jar wchanger.jar

And this is the solution I came up with:

taskkill /f /im "javaw.exe"

The problem with this is that closes every javaw process running on the pc.

I though I could name the process whatever I want, but that doesn't seem to be possible on windows.

  • Can I ask how you change the background? Just out of interest; I tried this by writing to a registry key that you find in a casual google search but on Win10 this doesn't update it. – rzwitserloot Oct 08 '18 at 23:36
  • I followed [this answer](https://stackoverflow.com/a/22819371/10475627), 0x0014 is the code for SPI_SETDESKWALLPAPER function [SystemParametersInfo](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-systemparametersinfoa) – Juli Allisio Oct 08 '18 at 23:56
  • You cannot terminate just a thread without shutting down the entire process. It's also not clear, why you are launching a thread at all. You know the time you want to perform an action, so set up a timer with appropriate timeout. – IInspectable Oct 09 '18 at 05:48
  • Sorry, I'll try to explain what Im trying to do a little better. When I open my program it starts the UI and a thread that checks if it has to change the wallpaper or not, and I open a thread because I want the program to keep checking after the UI is closed. I want to shutdown the entire process (that would be that thread and the UI if still open). My problem is that when I kill javaw.exe, it closes all java processes (even those that are not part of my program). I'm trying to close only the process that my program opens. – Juli Allisio Oct 09 '18 at 07:08

0 Answers0