6

I have a very basic VBS script that I plan on using frequently on my Windows 7 machine. Is there any way I can bind it to a keyboard shortcut so I don't have to navigate to it through Explorer obnoxiously.

I realize this question does not directly pertain to programming, or even scripting for that matter, but I could not find a straight answer online or through my own experimentation. I'm sure that there is a simple solution somewhere...

Thank you for taking the time to read, and hopefully respond to my inquiry. Evin Ugur.

deadboy
  • 849
  • 2
  • 9
  • 28

2 Answers2

5

Windows does have built-in support for shell shortcut keys, where a keypress is used to invoke an *.lnk file that launches your VBScript (using either cscript or wscript).

Create a shortcut file, have it invoke your VBScript file directly or run cscript or wscript with the appropriate arguments, then save it and open its Properties sheet and set a keystroke in the "Shortcut key" field (I suggest something like Ctrl+Alt+K).

Like so:

Screenshot of Windows' shortcut properties window

Then, whenever you press Ctrl+Alt+K, regardless of the active application, your script will be invoked.

A more heavy-duty alternative is AutoHotKey: http://www.autohotkey.com/

Dai
  • 141,631
  • 28
  • 261
  • 374
  • Thank you, creating a shortcut file solved my problem. It seems a bit counterintuitive to create hotkeys to a pointer, but I'm sure the abstraction layer allows for some OS flexibility somewhere. Thanks again! – deadboy Nov 14 '12 at 01:46
  • @deadboy It's not an abstraction - it's just that Windows only indexes `*.lnk` files for use with hot-keys (because the `*.lnk` file's internal data contains the hotkey). The only way to store shortcut keys for other files (documents or executables) would be to store the shortcut key info in an NTFS Alternate Data Stream, which isn't portable between file-systems. Shortcuts directly to programs aren't that useful as there'd be no way to specify command-line arguments or a working-directory, which **.lnk` files also allow. – Dai Jun 24 '20 at 12:54
  • @deadboy I feel the only counterintuitive thing about `*.lnk` files is that Windows' discovery and indexing of `*.lnk` files in the filesystem is under-documented voodoo. I really would prefer a central list of shortcut-keys in the HKCU registry or plaintext config file (e.g. JSON, XML or CSV) in `AppData\Local`. – Dai Jun 24 '20 at 12:55
0

Just as an FYI. I tried this and I was not able to register the hotkey when I had the Icon in a costume folder. Even if I added the hotkey, it failed to work.

Once I moved the icon to the "C:\ProgramData\Microsoft\Windows\Start Menu\Programs", the hotkey started to work.

Lonolian
  • 134
  • 1
  • 11