Batch file - windows explorer glitch

July 6, 2012 at 10:18:19
Specs: Windows XP SP3
Windows Explorer (Windows XP SP3) regularly changes the display from 'details' to 'icons'. I want to write a batch file to save repeatedly going through the same steps which are -
explorer.exe
pause
view
pause
details
pause
tools
pause
folder options
pause
view
pause
apply to all folders
pause
yes
pause
ok
pause
but I don't know how to turn those instructions into a batch file. Help please?

See More: Batch file - windows explorer glitch

Report •

#1
July 6, 2012 at 21:31:30
native batch can't send keystrokes into windows, it's only designed for the commandline environment (strictly text-based). Vbscript can do what you want, but the best solution would be a correction of the basic flaw. You prob'ly did, but did you check this: under Tools\Folder Options\View: "remember each folder's view settings" (checkbox checked).
These settings have to be stored of course, but i just don't know where. Someone else here most likely does know.
At any rate, here's vbscript front-end to "sendkeys" that uses a "script" to drive sendkeys. It allows delays (or pauses) between keystrokes.
'-------------------- snip1: begin vbscript next line
set fso=createobject("scripting.filesystemobject")
set wshell=wscript.Createobject("wscript.shell")
fil=wscript.arguments(0)
If Right(RTrim(fil), 1) = "?" Then
wsh.run "notepad sendkey.hlp"
wscript.quit
End If
'this is the driver-file, spec on the commandline: CSCRIPT SENDKEY.VBS file
set script=fso.opentextfile(fil,1)
'1st line is program to run, or null if pgm already running
pgm=script.readline
'2nd line is window: use 1 mostly for "regular" window
signal=script.readline
'3rd line is the string used to find the window, from the window title-bar
'OR the process-id (from tasklist)
windo=script.readline
If signal = "" Then signal = 1
If pgm <> "" Then
wshell.run pgm,signal,false
wscript.sleep 400
End If
wshell.AppActivate windo
'arbitrary 1-second wait (for the window to establish)
wscript.sleep 1000
'the rest of the keyscript is keystrokes and delays (unquoted numbers)
Do While Not script.atendofstream
k=script.readline
test=0
'test for number
on error resume next
test=cint(k)
If test>0 Then
wscript.sleep test
Else
wshell.SendKeys (k)
End If
Loop
'----------------snip1 end: end of vbscript

the keystrokes to drive explorer and achieve your specific objective:
---------------------snip2: keystrokes file begin next line
EXPLORER
1
1248
%V
1000
n
1000
%t
1000
o
1000
+{tab}
1000
{right}
1000
{tab}
1000
{enter}
1000
Y

:---------------- snip2 end: end of keystrokes file
If explorer is already running, leave line 1 blank, otherwise sendkey.vbs will start a new instance. explorer seems to always be pid# 1248, on my system, so that's what i used, but yours may differ (refer: tasklist.exe)
here's the helpfile, in case you want it:
------------------------- snip3: help file begin
Usage: sendkey [path+file]
The given file provides the keystroke script that drives the program.
The file's format consists of 3 leading or "header" elements, followed by
any number of data elements. Any element, whether header or data, is optional,
none are required, BUT you must reserve an empty spot for each header element.
Elements are separated by newline (each on its own line).
- CONTROL/SCRIPT FILE FORMAT -
HEADER:
1) program to start/run, incl. any commandline data: f/e: notepad test.txt
2) program window style: 0: hidden, 1: normal 2: icon 3: maximized
note: if window-style is zero, the window cannot be accessed for sendkey
3) title of window to which keys will be sent, matches any window up to
length of string given so be specific enough to get the right one.
OR the process-id (from tasklist)
DATA (SCRIPT):
4...) DATA: keystrokes and delays, mixed/assorted as needed:
Any unquoted integer is interpreted as a DELAY element, in miliseconds (1000=1 second)
Keystroke(s): Any quoted item or non-integer item (quoted or not) is interpreted
as a keystroke to send. For more detail, refer to "KEYS" below.
To send a dbl quote, enclose it in braces, like: {"}
Note: Some combinations, such as and especially, shift+tab, or: +{tab} will
fail unless quoted. To send a shifttab: "+{tab}"

Example: say you want to send the word "testing", then ENTER (newline),
then "line, two", a quoted "goodbye", then a 1-sec. delay, then alt-e,a into Notepad,

notepad
1
Untitled
testing
{enter}
"line, two"
{enter}
{"}
goodbye
{"}
400
%e
a


KEYS:
Nothing is sent into the window except exactly what you specify in the list.
When the end of the list is reached, control reverts to manual (user interactive).
"regular" keys are standard printable keys other than (){}[]^%+
Specify any regular keys like (examples): A, AB, AB76, A:B, A/?X&
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses ( )
have special meanings to SendKeys. To specify one of these characters,
enclose it within braces. For example, to specify the plus sign, use {+}.
To send brace characters, use {{} and {}}.
Brackets ([ ]) must also be enclosed in braces as well, because some other
applications use them.

To specify characters that aren't displayed when you press a key (such as
ENTER or TAB) and keys that represent actions rather than characters, use the
following table: (note, these are NOT case sensitive)

Key Code
--------------------------------
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER} or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS {INSERT}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1..F16 {F1}..{F16}
To specify keys combined with any combination of the SHIFT, CTRL, and ALT,
precede the regular key code with one or more of the following codes:
+ = SHIFT, ^ = CTRL, % = ALT. F/e: %{f4} for the end-pgm seq ALT-F4

To specify that any combination of SHIFT, CTRL, and ALT should be held down
while several other keys are pressed, enclose the code for those keys in
parentheses.
F/e, to send SHIFT-EC (SHIFT held down while E and C are pressed), use: +(EC)
To specify to hold down SHIFT while E is pressed, followed by C without SHIFT,
use: +EC
To specify repeating keys, use the form: {key number}. You must put a space
between key and number. For example, {LEFT 42} means press the LEFT ARROW key
42 times; {h 10} means press h 10 times.

SendKeys can't send keystrokes to an application that's not designed to run in
Windows. Sendkeys can't send the PRINT SCREEN (PRTSC) key to any application.
----------------------snip3 end: end helpfile


Report •

#2
July 8, 2012 at 04:53:04
Thanks. The "remember each folder's view settings" has been set for many months but the view keeps on reverting to 'icons'. VBscript is totally new to me. I need to decide whether continue to reset the view to 'details' every couple of days or to learn VBscript. Wikipedia states "VBScript has been installed by default in every desktop release of Microsoft Windows" so, presumably, I have it already. Is it easy to learn? If "Yes", how do I start VBscript? and how to type in the instruction included in your reply and get it working?

Report •

#3
July 8, 2012 at 08:33:00
Suggestion: Don't use registry cleaners. Go psychic powers?

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
July 8, 2012 at 13:56:43
to use the script, first save it: cut/past the script (beginning line "set fso" down
to 'end of vbscript) into a text file with extension .VBS (f/e: sendkey.vbs)
cut/paste the keystrokes file (begins with line EXPLORER, ends with the last {enter} before a blank line) into another text file of any desired name (f/e: keys)
To run the script, from command prompt, type:
CSCRIPT /NOLOGO sendkeys.vbs keys
If all goes well, you should see explorer start up and the keystrokes sent into it. You can put the CSCRIPT command above into a batchfile to save typing.
(I raised the delays in the keystrokes from 100 to 1000so you can see what's happening). If you want the help feature, cut/paste the help section into file "sendkey.hlp". Also, on my xp system, vbs files no longer need the CSCRIPT to run, they will run like batchfiles straight from the prompt. use CSCRIPT /? to see commandline options.
Also, you might try: uncheck the "remember" box, "apply", then re-check and re-apply. Maybe it will "stick"!
ps: if you are interested in learning vbscript, I recommend download a copy of "script.chm", (it's somewhere on msdn site, not sure, if you can't find it I'll send you a copy of mine.)

Report •

Ask Question