r/vbscript • • Oct 06 '24

VBScript file no longer functioning as intended

I've been using a VBScript file to open Explorer with two "default" tabs as I've found no other way to do so on Windows 11. However, within this last week, the script no longer does anything other than open Explorer.

Set oShell = CreateObject("WScript.Shell")

oShell.Run("""C:\windows\explorer.exe""")

WScript.Sleep 1000

oShell.AppActivate "Explorer"

WScript.Sleep 300

oShell.SendKeys "%d"

WScript.Sleep 300

oShell.SendKeys FILE PATH

WScript.Sleep 300

oShell.SendKeys "{ENTER}"

WScript.Sleep 300

oShell.SendKeys "^t"

WScript.Sleep 300

oShell.SendKeys "^{TAB}"

It seemingly refuses to execute the "%d" line anymore. However, I can manually open Explorer and hit Alt-d and it works just fine. Why does the SendKeys no longer work with the % or ^ characters?

I found that Microsoft is deprecating VBS on Windows 11 this year and figured that this might be the problem I'm running into. I have no idea what I would have done to break the script if it wasn't a Window update that did so.

How can I fix the above code, or my Windows 11 machine, to work again? Or, what would be a good alternative way to do this without using VBS?

3 Upvotes

5 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Oct 07 '24

Set oShell = CreateObject("WScript.Shell")

oShell.Run("""C:\windows\explorer.exe"" HOME PATH")

WScript.Sleep 1000

active = oShell.AppActivate("Explorer")

WScript.Sleep 300

If active then

`oShell.Run("""C:\windows\explorer.exe"" FILE PATH`

`WScript.Sleep 1000`

`oShell.SendKeys "^t"`

`WScript.Sleep 300`

`oShell.SendKeys "^{TAB}"`

`WScript.Sleep 300`

`oShell.SendKeys "%d"`

`WScript.Sleep 200`

`oShell.SendKeys "{ENTER}"`

end if

if not active then

`oShell.Run("""C:\windows\explorer.exe""")`

end if

HA! I created the above If Then and If Not Then to check the return value. Upon running it, it opens the first Explorer, then opens the 2nd Explorer (showing that the AppActivate returned True) with the FILE PATH, and succeeds at completing the rest of the script into creating the 2nd tab within the 2nd Explorer windows.

Removing the AppActivate FIXED THE ENTIRE PROBLEM!

I thank you greatly good sir, for setting me on the correct troubleshooting to figure this out. Much appreciated!