Hi
@CptRootBeard
Wow, this is such a good reply - thanks
. Taking your thoughts in turn:
I personally couldn't find a way to run a simple search directly through the Shell object, and anything I tried with control send wasn't any better than what you have.
Ah, at least it's not just me then
.
You still have a couple (very similar) options here. Both make use of the search-ms application protocol, and thus will open the search in a new window.
Woa, this is all totally new to me, but turns out to be perfect
.
Do some searches in explorer, then click the address bar when viewing the results. You'll get a URL that you can parse out to what you need.
Running or navigating to that URL will open a new explorer window with a search underway.
I so love it when someone points out 'goodies' on a thing that I've been doing for years without realising it was there - who knew clicking in the address bar would reveal all this goodness!!
I'd lean towards Run(), personally.
Right, I experimented with all the code you kindly provided. It seemed to me (naively maybe?) that the
Run() approach seems to work just as well. And I'm wanting a new Explorer window with each search, so it's also perfect in that regard. So I pared down your code, and slightly re-jigged it for my purpose and it seems to work brilliantly. Here it is in case it's useful for anyone else:
Code: Select all
searchText := "IMG-20170518-WA0000"
searchLoc := "D:\AutoHotKey\My AHK projects\PhotoScanner\Test photo files"
searchLocShort := "\Test photo files"
searchTitle := "Looking for <" . searchText . "> in <" . searchLocShort . ">"
URL := "search-ms:displayname="
URL .= cleanForURL(searchTitle) . "&crumb=System.Generic.String"
URL .= cleanForURL(":" . searchText) . "&crumb=location:"
URL .= cleanForURL(searchLoc)
Run(URL)
cleanForURL(stringIn) {
FormattedURL := StrReplace(stringIn, " ", "%20") ;remove spaces.
FormattedURL := StrReplace(FormattedURL, ":", "%3A") ;remove colons.
FormattedURL := StrReplace(FormattedURL, "\", "%5C") ;remove backslashes.
return FormattedURL
}
As with most things, be mindful of how you use the protocol - it's recently been abused by bad actors.
Because of this, some systems may have the protocol disabled.
Okay, I'm not in any loop that would tell me about this. Shame that there are always peeps looking for bad outcomes! Anyway the good news is that it seems to work magnificently on my machine.
So, huge thanks for taking the time to educate me on this protocol and for providing code that does the job right-off - very much appreciated
.