title: Infinite batch call when starting a batch file from Java
body: <p>I've created the following script, which has the purpose to install &amp; configure a Windows Service. When called, Windows brings up the UAC window which must be acknowledged by the user to continue the process.</p>
  
  <pre><code>@echo off
  CALL "%~dp0.\installAnchorService.exe"
  sc config "FLEXnet Licensing Service" start= auto
  </code></pre>
  
  <p>The problem is, that normally the batch file isn't started in administrator mode. I already found a solution for that here: <a href="https://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file">How to request Administrator access inside a batch file</a>.</p>
  
  <p>This works fine when i start the bat-file directly with double-click. When i start it via Java, the script falls into an endless loop. Somehow the VBS creation fails. Do I have to call my batch script in a special way that it's executed correctly in java? My approach was:</p>
  
  <pre><code>ProcessBuilder builder = new ProcessBuilder("cmd", "/c", "start", "createService.bat");
  builder.start();
  </code></pre>
  
  <p>Any thoughts/hints are appreciated...</p>
  
  <p>Full script:</p>
  
  <pre><code>@echo off
  
  :: BatchGotAdmin
  :-------------------------------------
  REM Check for permissions
  &gt;nul 2&gt;&amp;1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  
  REM If error flag set, we do not have admin.
  if '%errorlevel%' NEQ '0' (
      echo Requesting administrative privileges...
      goto UACPrompt
  ) else ( goto gotAdmin )
  
  :UACPrompt
      echo Set UAC = CreateObject^("Shell.Application"^) &gt; "%temp%\getadmin.vbs"
      set params = %*:"=""
      echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 &gt;&gt; "%temp%\getadmin.vbs"
  
      "%temp%\getadmin.vbs"
      del "%temp%\getadmin.vbs"
      exit /B
  
  :gotAdmin
      pushd "%CD%"
      CD /D "%~dp0"
  :--------------------------------------
  
  CALL "%~dp0.\installAnchorService.exe"
  sc config "FLEXnet Licensing Service" start= auto
  </code></pre>