I want to check within my Java application whether the windows virtual keyboard is already running or not.
I searched for it and found, that I can use wmic.exe
to search for a process.
This is what I'm doing:
Process proc = Runtime.getRuntime().exec("wmic.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(proc
.getInputStream()));
OutputStreamWriter oStream = new OutputStreamWriter(proc
.getOutputStream());
oStream .write("process where name='osk.exe' get caption");
oStream .flush();
oStream .close();
input.readLine();
while ((in = input.readLine()) != null) {
if (in.contains("osk.exe")) {
input.close();
proc.destroy();
return;
}
}
input.close();
proc.destroy();
This is working, but wmic
is somehow creating the file TempWmicBatchFile.bat
with the line process where name='osk.exe' get caption
.
How can I prevent this from happening?