0

As the title reads, I am struggling to get a simple WScript .VBS script with send keys to activate correctly.

I have a HTPC and I operate everything from a Harmony remote and hub except for a single occasion where I need to use Ctrl + J to bring up MadVR statistics during video playback.

The Harmony remote allows me to activate a taskbar shortcut from a button press. Therefore, I created a VBS script with the following command:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^j"

I placed the VBS script into a folder on my C drive and then created a shortcut from the script and attached it to my taskbar.

Sadly this doesn't appear to work and I'm curious as to why not.

I would appreciate some assistance in either troubleshooting this or finding an alternative method to call these key commands.

Cheers

1
  • 2
    AutoHotkey is a good alternative for anything related to shortcut keys or compact scripts that need to perform dedicated functions
    – JJohnston2
    May 5, 2018 at 16:11

1 Answer 1

0

Sadly this doesn't appear to work and I'm curious as to why not.

Whenever you attempt to pin (at least some) scripts (e.g. VBS, Python) to the taskbar, a pin for the interpreter is created instead. This applies to pinning any shortcut for these types of scripts as well.

Windows appears to do this under the assumption that you may wish to run multiple scripts from the same pin (i.e. if you pin a script directly to the taskbar, a pin to the interpreter is created [as noted], but the script itself is shown under the "Recent" or "Pinned" lists if you immediately right-click the pinned item).

I would appreciate some assistance in troubleshooting this.

In order to make things work as you intend, you need to edit the target of the pinned shortcut by:

  • Right-clicking the pinned item.

  • Selecting the interpreter entry and right-clicking again.

  • Choosing Properties and editing the Target field in the Shortcut tab.

Pinned Shortcut Properties

Pinned Shortcut Shortcut Tab

In your case, you should change the Target from e.g.:

C:\Windows\System32\wscript.exe

To:

C:\Windows\System32\wscript.exe "C:\path\to\your\key_script.vbs"

Make sure to click Apply after changing the Target. Press Ok to close the window when finished.

Notes

  • Simply appending the full path of the script (in quotes) to the interpreter entry should be sufficient to run most scripts. That said, some interpreters may require additional command switches to run a script properly.

  • For batch files (.bat), Windows apparently doesn't allow scripts or shortcuts to scripts to be pinned directly. You must pin e.g. C:\windows\system32\cmd.exe (or %SystemRoot%\system32\cmd.exe) first, then edit the pin as mentioned above. The final Target should look like:

    C:\windows\system32\cmd.exe /c "c:\path\to\your\script.bat"
    

    where /c tells cmd.exe that it should only run the command listed and then immediately close itself.

  • If you are still having trouble, there may be another problem (such as window focus). As is, the .vbs script itself seems to work (it sends Ctrl + J without issue).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .