title: Check if desktop window is in foreground using .bat
body: <p>I am trying to create a shortcut through which i can toggle 'Show desktop' and also and if the program is run through desktop 'hide desktop icons' so here is my .bat file</p>
  
  <pre><code>set mypath=%cd%
  cd C:\Program Files\oneClickHD\
  start ShowDesktop.lnk
  if "%mypath%"=="C:\Users\admin\Desktop" goto GO
  :GO
  start HideDesktopIcons.exe
  </code></pre>
  
  <p>this piece of code doesn't really work as dir of bat wont change if i use its shortcut to run it so i thought of 3 methods but cannot implement them these methods are :</p>
  
  <p>1)detect if there is any window is open if yes then toggle showdesktop.lnk
    or if current foreground window is not desktop toggle </p>
  
  <p>2)check if desktop is on foreground and if yes run hideIcons.exe </p>
  
  <p>3)instead of using showdesktop.lnk that toggles show desktop use something that just opens up desktop </p>
  
  <p>to find solution i tried using nircmd through which i couldn't find how to return value of active windows or check if desktop is active and there is a commend in that : nircmd win min alltopnodesktop 
  which is the only one that seems to work but it minimizes everything and i could only see wallpaper it just works in weird way.
  then i also thought of using vbs scripting but found better to use .bat for windows related things.
  then i also tried using powershell but it doesnt seem on my pc .</p>