0

Hi I saw this question How can I get the current active window at the time a batch script is run?

but didnt quite get what i wanted. They have given jscript and powershell script answers...so cant we get the path of the active window opened on the screen using dos commands.

Please help.

have tried - %cd% :: but it gives the path where the batch file is located not the folder that is currently opened and active on the desktop

Community
  • 1
  • 1
  • Sorry--no, there is no way to do that with pure batch. – Tony Hinkle May 27 '15 at 19:57
  • `%CD%` gives the current working directory. That _can_ be where the batch file is located. But, it can also be elsewhere. For instance, when the mybatch.bat file is executed using: `c:\>c:\bin\mybatch.bat` - calling `%CD%` from within mybatch.bat will output `c:\ `.. – kodybrown May 27 '15 at 20:04

1 Answers1

0
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each window in AllWindows
    outp.writeline window.locationname
Next

to use

cscript /nologo c:\pathtoscript\script.vbs

Note it does Explorer and Internet Explorer windows for historical reasons - they used to be the same program.

Which gives output like this

Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\David Candy>cscript /nologo "C:\Users\David Candy\Documents\Assorted\Sc
ripts\ListOpenShellWindowsStdOut.vbs"
Newest 'batch-file' Questions - Stack Overflow
dos command or batch file to get the path for the current active folder opened o
n my screen - Stack Overflow
Music
Favorites

To get into a batch variable use a for loop

for /f "delims=" %%A in ('cscript // nologo script.vbs') do Echo %%A