title: Get foreground windows of windows explorer to retrieve the url
body: <p>I think am close to the solution, or in the general ball park, but the way am calling the powershell might be part of the issue am calling the ps1 from a batch file, to </p>
  
  <p>I want to have the user click a button and then have powershell get the url of the active window (EXPLORER.exe) - i did try to but the start/sleep command to check in the ISE but could get it to work :( could you help be out ?</p>
  
  <p>Thank You </p>
  
  <pre><code>Set-ExecutionPolicy RemoteSigned
  Param(
  )
  Add-Type @"
  using System;
  using System.Runtime.InteropServices;
  public class UserWindows {
  [DllImport("user32.dll")]
  public static extern IntPtr GetForegroundWindow();
  }
  "@
  try {
  $ActiveHandle = [UserWindows]::GetForegroundWindow()
  $Process | Select LocationURL| select -ExpandProperty LocationURL -First 1 | 
  Tee-Object -Variable "dirvar"
  } catch {
  Write-Error "Failed to get active Window details. More Info: $_"
  }
  $dirvar1 = "$dirvar" -replace 'file:///', '' 
  echo "$dirvar1"
  Start-Process "Z:\30_Sysadmin\ADB_LOADER_DIR\ADBDIR.bat" "$dirvar1"
  </code></pre>