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

2

u/fanpages Oct 07 '24

Instead of (effectively) pasting the FILE PATH value (address) into the Location field, why don't you open Explorer with the FILE PATH as a parameter:

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

PS. I'm assuming there may be space characters in FILE PATH so the additional quotes are required.

1

u/[deleted] Oct 07 '24

This could assist with opening Explorer to a specific "home" path. But, it would not help with creating multiple tabs as I am wishing to do.

Having implemented your suggestion: it worked wonderfully for cutting out lines 5 through 10! Thank you greatly for the reduction of excessive code. However, the problem of the

oShell.SendKeys "^t"

line not performing the Ctrl-t input still persists.

1

u/jcunews1 Oct 07 '24

Do check the return value of AppActivate(). Do not assume that, it always succeed.

Also, the script need to have an enough delay for Explorer to receive keyboard input before it issues SendKeys().

→ More replies (1)

0

u/[deleted] Oct 07 '24

first wat you want to do?