(new-object -com shell.application).FindFiles(); $wsc = (new-Object -ComObject wscript.shell); Start-Sleep -m 200; $wsc.sendkeys("Filename{enter}")
Hi,
Why all of that? Use Get-ChildItem instead:
What does "I want to open a GUI" mean?
What is the purpose/goal of the script? In other words, tell what you want to do, not how you think you need to do it.
What does "I want to open a GUI" mean?
What is the purpose/goal of the script? In other words, tell what you want to do, not how you think you need to
The FindFiles method you are using does not have any parameters, so you can't "type" automatically into the "find" box. It is likely that you simply cannot do this the way you thought you were going to be able to do it, at least not with built-in script
Bill, I respectfully disagree. Run the code in my original post. It will type "Filename" in the search window and run the search. I imagine if there's a way to do that in the search box, there has to be a way to tell it what folder to search in.
The issue you'll face is that SendKeys is completely unreliable, as you have no way to force what window or input box has focus to receive your sent keystrokes. It might work while you're testing it, but I guarantee you it'll break later.
I don't have any real additional information to add here, but I just wanted to point this out so you're at least aware of the possible problems.
Bill,
Thank you. I was not aware of that "issue" with SendKeys.
I imagine if there's a way to do that in the search box, there has to be a way to tell it what folder to search in.
There doesn't have to be a way. Also, as noted, SendKeys is notoriously unreliable.
As noted: I don't think you're going to be able to get the results you want from built-in scripting tools.
Dim SheetNum As String
SheetNum = ActiveCell.value
Call Shell("explorer /root,""search-ms:query=" & SheetNum & "&crumb=location:" & RootDir & "&""")
RootDir is also a string, set as to a constant directory location.
Adapted from a PS command someone provided me with:
Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run ("explorer /root,""search-ms:query=exe&crumb=location:C:\Windows&""")
Dim SheetNum As String
SheetNum = ActiveCell.value
Call Shell("explorer /root,""search-ms:query=" & SheetNum & "&crumb=location:" & RootDir & "&""")
RootDir is also a string, set as to a constant directory location.
Adapted from a PS command someone provided me with:
Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run ("explorer /root,""search-ms:query=exe&crumb=location:C:\Windows&""")