title: Need to stop the user click the exe for the second time, while it is already running
body: <p>I have developed a exe of my Java application, and run it from a thumb drive. It will take some time to execute. But my end user thinks it is not running and clicks for the second time. I need to stop this. I need to stop continuous click on the exe, while it is running. I used the shell script to check whether the exe is running or not.  And displays the message, that the exe is already running. And stops the further process. I need this to be happened while exe is running for the second time. I couldn't figure this out. Is there any way to disable the exe from click, while it is running. Or how can I use the check whether it is running or not.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileWriter;
  import java.io.InputStreamReader;
  
  
  public class VBSUtils {
  
        private VBSUtils() {  }
  
        public static boolean isRunning(String process) {
          boolean found = false;
          try {
              File file = File.createTempFile("realhowto",".vbs");
              file.deleteOnExit();
              FileWriter fw = new java.io.FileWriter(file);
  
              String vbs = "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
                         + "Set locator = CreateObject(\"WbemScripting.SWbemLocator\")\n"
                         + "Set service = locator.ConnectServer()\n"
                         + "Set processes = service.ExecQuery _\n"
                         + " (\"select * from Win32_Process where name='" + process +"'\")\n"
                         + "For Each process in processes\n"
                         + "wscript.echo process.Name \n"
                         + "Next\n"
                         + "Set WSHShell = Nothing\n";
  
              fw.write(vbs);
              fw.close();
              Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
              BufferedReader input =
                  new BufferedReader
                    (new InputStreamReader(p.getInputStream()));
              String line;
              line = input.readLine();
              if (line != null) {
                  if (line.equals(process)) {
                    found = true;
                  }
              }
              input.close();
  
          }
          catch(Exception e){
              e.printStackTrace();
          }
          return found;
        }
  
  
  
  }
  </code></pre>
  
  <p>And In my main class, I called VBUtils.</p>
  
  <pre><code> boolean result = VBSUtils.isRunning("myexe.exe");
  if(result)
  {
       msgBox("myexe is running. Please wait");
  }
  else
  {
   // my part of execution.
  }
  </code></pre>
  
  <p>If I call like this, the exe got terminated. Both the first and second execution. </p>