Page 1 of 1

[RESOLVED / ALTERED] Windows Explorer ignores sending Backspace to it and doubles its process when started \

Posted: 13 Jan 2023 12:51
by DOSadnie
I wrote this script [as the first step] to get access to Recycle Bin system folder

Code: Select all

cd C:\Windows
start explorer.exe
%SendKeys% {TAB}{TAB}{TAB}{ENTER}
"%userprofile%\Desktop\Recycle Bin.lnk"
It works- i.e. it opens window of Window Explorer; but with a caveat, as it also opens second window with system location This PC. Being there I can manually press Backspace and end up in the Desktop folder with focus placed on Recycle Bin folder - which is exactly what I need

But the next part of my intended macro script simulating the above does not work. And that is because

Code: Select all

%SendKeys% {BACKSPACE}
is ignored. And thus it is futile to add the pivotal line

Code: Select all

%SendKeys% ^Z
which holds the whole purpose for this shebang: I need to simulate pressing of CTRL+Z on the Recycle Bin folder in order to un-delete the last item or items sent to oblivion

And then finally I would also need to somehow close this particular Window Explorer window


I tried using variants

Code: Select all

%SendKeys% {BS}
and

Code: Select all

%SendKeys% {BKSP}
which are listed here https://learn.microsoft.com/en-us/previ ... 3(v=vs.84)] but to no avail. I also have noticed that the line

Code: Select all

%SendKeys% {TAB}{TAB}{TAB}{ENTER}
is apparently somewhat unnecessary and can be completely omitted


And thus - to sum up:

Code: Select all

cd C:\Windows
start explorer.exe
"%userprofile%\Desktop\Recycle Bin.lnk"
%SendKeys% {BACKSPACE}
%SendKeys% ^Z
#1] is unable to push Backspace to Windows Explorer showing the content of Recycle Bin
#2] opens unnecessary second window of Window Explorer showing the content of This PC
#3] lacks commands to close the recently opened Window Explorer window

Please help me

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 13 Jan 2023 15:10
by OJBakker
Open the recycle.bin with

Code: Select all

start "" explorer.exe shell:RecycleBinFolder
And close explorer with Alt-F4

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 14 Jan 2023 03:05
by DOSadnie
This took care of the second unnecessary window

But still I am unable to successively send keys

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 14 Jan 2023 03:24
by OJBakker
You need to wait with sending keys until the explorer is started and the recyclebin is available.
So add a timeout command before trying to send keys.
Then send Ctrl-Z to restore the files.
Then close explorer with Alt-F4.

If this does not work show us your entire script.

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 14 Jan 2023 09:54
by DOSadnie
I had already tested way back the timeout and it does nothing - i.e. the CMD window just sits behind the window of Windows Explorer counting down, which CMD window is always opened without any delay. Running the script as Administrator also does not help. I also tested running it from within Windows Explorer to rule out as culprit my 32-bit file manager [as I am running on 64-bit version of Windows 10]

The whole script looks now like this:

Code: Select all

cd C:\Windows
start "" explorer.exe shell:RecycleBinFolder
timeout 5
%SendKeys% ^Z
%SendKeys% %{F4}

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 14 Jan 2023 10:57
by OJBakker
Your script is incomplete.
The variable %SendKeys% is not defined in your script but used in the last 2 lines.
Add a pause as the last line.
Then you can see what happens when cmd tries to process your sendkeys lines.

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 15 Jan 2023 14:09
by DOSadnie
Well among other topics and batch examples I found this "simple enough to be understand with no problems" code

Code: Select all

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Start the other program in the same Window
start "" /B cmd

%SendKeys% "echo off{ENTER}"

set /P "=Wait and send a command: " < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "echo Hello, world!{ENTER}"

set /P "=Wait and send an Up Arrow key: [" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{UP}"

set /P "=] Wait and send an Enter key:" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{ENTER}"

%SendKeys% "exit{ENTER}"

goto :EOF


@end


// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
at https://stackoverflow.com/questions/170 ... 5#17050135, but because me molto stupido [https://www.youtube.com/watch?v=IwwBM8na1c4] thus I was not able to rework it to my needs


But I was able to rework this VBS script

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9 

Code: Select all

' Give Notepad time to load
WScript.Sleep 500
 
Dim Msg: Msg = "Hello, World!"
 
' Type in One Character at a time
For i = 1 To Len(Msg)
    WScript.Sleep 200
    WshShell.SendKeys Mid(Msg, i, 1)
Next
 
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "%{F4}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
found at https://helloacm.com/send-keystrokes-to ... dkeys-wsh/ to my needs:

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "explorer.exe shell:RecycleBinFolder", 9

WScript.Sleep 1111

WshShell.SendKeys "^z"
WshShell.SendKeys "%{F4}"
This works almost A-OK - as the only caveat is to not to repeatedly click it to too fast trying to execute it multiple times, because it causes the file manager from within which I click on this script to close window of that manager instead of Windows Explorer [which I guess could be avoided if this VBS script would not send those keys to windows with an improper title]

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 28 Jan 2023 05:35
by DOSadnie
DOSadnie wrote:
15 Jan 2023 14:09
[...]
But I was able to rework this VBS script
[...]
Which, as it turns, executes Undo in Windows Explorer and not just Un-delete - thus when used without a care can results with chaos

And thus I still have the problem of
OJBakker wrote:
14 Jan 2023 10:57
[...]
variable %SendKeys%
[...]
which I failed at defining

Re: Windows Explorer ignores sending Backspace to it and doubles its process when started

Posted: 01 Jul 2023 07:43
by DOSadnie
I decided to leave this script, as it is - i.e. to execute with it the broader un-do task [which includes un-delete], because very rarely I also by mistake I inadvertently drop something to some location [like when suddenly wireless mouse deciced to loose its connection for a split second]

And so with this

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "explorer.exe shell:RecycleBinFolder", 9
WshShell.Run "explorer.exe shell:RecycleBinFolder", 0, True

WScript.Sleep 1111

WshShell.SendKeys "^z"
WshShell.SendKeys "%{F4}"
I can just execute a single VBS file that will undo both kinds of mistakes [accidental deletion and movement] and also unwanted copy if needed