Long time time reader, first time poster. I recently wrote a batch program utilizing sendto parameters (%*), that would end with the batch program bringing up the working windows folder back to the forefront. I'm not interested in using autohotkey to do it, although I have to admit I recently discovered that gem from this website, and it's great!
Utilizing a recent discovery of having .bat create a temp vbs script by echoing out the commands to temp vbs script and then running it and closing it, I had an idea to do the same thing with bringing the working window to the forefront. However, it is exhibiting very odd behavior when echoing out the text to the vbs script. I have a feeling it has to do with delayedexpansion.
I have included some comments where I'm seeing some of this odd behaviour.
Code: Select all
REM echo out the first line of the vbs script
echo Set objShell = CreateObject("WScript.Shell") > WINDOWFOCUS.vbs
SETLOCAL enableExtensions enableDelayedExpansion
REM Get the filepath from %* parameter
FOR /F "delims=" %%i in (%*) do (
REM for some reason this will break if the next line doesn't include the oddball 3rd double quote
SET "filepath=%%~dpi""
REM This removes backslash.. -1 doesn't work have to use -2 which seems odd
SET "filepath=!filepath:~0,-2!"
REM this seems unnecessary to assign varpath as a variable but !filepath! won't work outside the loop.
SET varpath=!filepath!
CALL :breakingloop
)
:breakingloop
REM http://stackoverflow.com/questions/774175/how-can-i-open-a-message-box-in-a-windows-batch-file
REM this line doesn't get completely echoed out to .vbs file
echo objShell.AppActivate("!varpath!")>> WINDOWFOCUS.vbs
call WINDOWFOCUS.vbs
pause
del WINDOWFOCUS.vbs
exit
so the final WINDOWFOCUS.vbs should look like this:
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate("C:\examplefolder")
If I create this vbs file myself, it runs as it should when I run it. It brings the folder into focus.
Any help would be greatly appreciated.