Re: automation of Windows Explorer search window

T

Todd Vargo

Marceepoo wrote:

> The vbscript below opens a Windows Explorer search window.
> The Windows Explorer search window has fields in which the user can insert
a

> search String Filter, and a search path String.
> I can't figure out what code to use to insert:
> 1. A search filter string in the field entitled "All or part of the
file

> name"; Or
> 2. A search path string in the field entitled: "Look in:"
>
> I tried using Sendkeys,
> (Alt-L = "Lookin in:" field)
> (Alt-O = Filename/filemask field, "All or part of the file name:")
> (Alt-R = "Search" button)
> But Sendkeys doesn't seem to trigger any action at all in the search
window.

>
> Any suggestions would be much appreciated.
>
> Marceepoo
>
> Dim objShell
> Set objShell = WScript.CreateObject("Shell.Application")
> objShell.FindFiles

This should help...

Dim objShell, WshShell
Set objShell = WScript.CreateObject("Shell.Application")
set WshShell = WScript.CreateObject("WScript.Shell")
objShell.FindFiles
WScript.Sleep 500
WshShell.AppActivate "Find: All files"
WScript.Sleep 500
WshShell.SendKeys "foo{tab}bar{tab}"
WScript.Sleep 500
WshShell.SendKeys "c:\windows{enter}"

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
 

My Computer

T

Tom Lavedas

On May 28, 11:09 pm, "Todd Vargo" <[email protected]> wrote:

> Marceepoo wrote:

> > The vbscript below opens a Windows Explorer search window.
> > The Windows Explorer search window has fields in which the user can insert
> a

> > search String Filter, and a search path String.
> > I can't figure out what code to use to insert:
> > 1. A search filter string in the field entitled "All or part of the
> file

> > name"; Or
> > 2. A search path string in the field entitled: "Look in:"
>

> > I tried using Sendkeys,
> > (Alt-L = "Lookin in:" field)
> > (Alt-O = Filename/filemask field, "All or part of the file name:")
> > (Alt-R = "Search" button)
> > But Sendkeys doesn't seem to trigger any action at all in the search
> window.
>

> > Any suggestions would be much appreciated.
>

> > Marceepoo
>

> > Dim objShell
> > Set objShell = WScript.CreateObject("Shell.Application")
> > objShell.FindFiles
>
> This should help...
>
> Dim objShell, WshShell
> Set objShell = WScript.CreateObject("Shell.Application")
> set WshShell = WScript.CreateObject("WScript.Shell")
> objShell.FindFiles
> WScript.Sleep 500
> WshShell.AppActivate "Find: All files"
> WScript.Sleep 500
> WshShell.SendKeys "foo{tab}bar{tab}"
> WScript.Sleep 500
> WshShell.SendKeys "c:\windows{enter}"
>
> --
> Todd Vargo
> (Post questions to group only. Remove "z" to email personal messages)

Todd,

You use Win98, don't you? I ask because in XP, the FindFiles caption
is "Search Results" which points out one of the many problems with a
Sendkeys application.

The closest I could get to a usable (?) solution was something like
this ...

Dim objShell, WshShell
CreateObject("Shell.Application").FindFiles
with CreateObject("WScript.Shell")
do until .AppActivate("Find: All files") or _
.AppActivate("Search Results")
wsh.Sleep 500
Loop
wsh.Sleep 2000
if .AppActivate("Search Results") then _
.Sendkeys "{Tab 5}{enter}" : wsh.Sleep 200
.SendKeys "foo{tab}bar{tab}" : wsh.Sleep 200
.SendKeys "c:\windows"
end with

I still don't like it because of the open loop two second delay
required (on my machine) between confirming that the search screen was
open and the time the first keystroke could be sent reliably to it
(under XP). Without the delay, I kept opening the Internet search
function, instead.

This is a case where AutoIt (third party control - google search to
find a free copy) might be almost essential.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 

My Computer

T

Todd Vargo

Tom Lavedas wrote:

> Todd Vargo wrote:
snip...

> > WshShell.AppActivate "Find: All files"
>
> Todd,
>
> You use Win98, don't you? I ask because in XP, the FindFiles caption
> is "Search Results" which points out one of the many problems with a
> Sendkeys application.

Thanks, I tend to forget to mention when code needs modified to suit an OPs
needs/OS. On the one hand, the code seems obvious (to me) so I forget, but
OTOH, SCRIPT56.CHM is available.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
 

My Computer

K

Keith Miller \(MVP\)

I just went to my XP machine & did a couple of searches, saved them, & then
examined the contents in notepad (hex editor would probably be better).

There is some binary gobbledygook but it seems to be constant -- and you
also see your search terms as both ascii & unicode strings.

You may be able to construct a saved search file with the terms you want &
then open that, avoiding the use of sendkeys.

--
Good Luck,

Keith
Microsoft MVP [Windows Shell/User]



"Tom Lavedas" <[email protected]> wrote in message
news:[email protected]

> On May 28, 11:09 pm, "Todd Vargo" <[email protected]> wrote:

>> Marceepoo wrote:

>> > The vbscript below opens a Windows Explorer search window.
>> > The Windows Explorer search window has fields in which the user can
>> > insert
>> a

>> > search String Filter, and a search path String.
>> > I can't figure out what code to use to insert:
>> > 1. A search filter string in the field entitled "All or part of the
>> file

>> > name"; Or
>> > 2. A search path string in the field entitled: "Look in:"
>>

>> > I tried using Sendkeys,
>> > (Alt-L = "Lookin in:" field)
>> > (Alt-O = Filename/filemask field, "All or part of the file name:")
>> > (Alt-R = "Search" button)
>> > But Sendkeys doesn't seem to trigger any action at all in the search
>> window.
>>

>> > Any suggestions would be much appreciated.
>>

>> > Marceepoo
>>

>> > Dim objShell
>> > Set objShell = WScript.CreateObject("Shell.Application")
>> > objShell.FindFiles
>>
>> This should help...
>>
>> Dim objShell, WshShell
>> Set objShell = WScript.CreateObject("Shell.Application")
>> set WshShell = WScript.CreateObject("WScript.Shell")
>> objShell.FindFiles
>> WScript.Sleep 500
>> WshShell.AppActivate "Find: All files"
>> WScript.Sleep 500
>> WshShell.SendKeys "foo{tab}bar{tab}"
>> WScript.Sleep 500
>> WshShell.SendKeys "c:\windows{enter}"
>>
>> --
>> Todd Vargo
>> (Post questions to group only. Remove "z" to email personal messages)
>
> Todd,
>
> You use Win98, don't you? I ask because in XP, the FindFiles caption
> is "Search Results" which points out one of the many problems with a
> Sendkeys application.
>
> The closest I could get to a usable (?) solution was something like
> this ...
>
> Dim objShell, WshShell
> CreateObject("Shell.Application").FindFiles
> with CreateObject("WScript.Shell")
> do until .AppActivate("Find: All files") or _
> .AppActivate("Search Results")
> wsh.Sleep 500
> Loop
> wsh.Sleep 2000
> if .AppActivate("Search Results") then _
> .Sendkeys "{Tab 5}{enter}" : wsh.Sleep 200
> .SendKeys "foo{tab}bar{tab}" : wsh.Sleep 200
> .SendKeys "c:\windows"
> end with
>
> I still don't like it because of the open loop two second delay
> required (on my machine) between confirming that the search screen was
> open and the time the first keystroke could be sent reliably to it
> (under XP). Without the delay, I kept opening the Internet search
> function, instead.
>
> This is a case where AutoIt (third party control - google search to
> find a free copy) might be almost essential.
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
 

My Computer

Top