batch file does not work with shortcut key

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rubing
Posts: 2
Joined: 20 Nov 2013 22:18

batch file does not work with shortcut key

#1 Post by rubing » 20 Nov 2013 22:25

Using Windows 7 and wrote a little batch script to open an image file of interest in the native Windows Photo Viewer, so basically am just using the command:

CALL somepic.png

This works fine when I click on the program or it's shortcut or enter it at the commandline. However, it does not work when I try to execute the program by shortcut command key (e.g. Ctrl-Alt-V) created under the shortcut's properties.

I don't have a problem running other batch files this way. any help appreciated!

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: batch file does not work with shortcut key

#2 Post by foxidrive » 21 Nov 2013 04:59

Try another key combination - maybe there is a clash.

Use this too: I'm not sure how call works with it at all.

Code: Select all

start "" pic.png

rubing
Posts: 2
Joined: 20 Nov 2013 22:18

Re: batch file does not work with shortcut key

#3 Post by rubing » 21 Nov 2013 12:16

Yes, it was a clash! When it first didn't work I suspected a clash and so tried a different lettter (m), unluckily that was also a letter that clashed...arrrrrrrgggghhhhhh...freaking windows!

Squashman
Expert
Posts: 4195
Joined: 23 Dec 2011 13:59

Re: batch file does not work with shortcut key

#4 Post by Squashman » 21 Nov 2013 13:27

That makes for an interesting question though. Is there a way to find all the shortcut keys assigned. I assume they all exist within the registry.

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: batch file does not work with shortcut key

#5 Post by AiroNG » 21 Nov 2013 13:52

see:


which, ultimately, will lead you here:
http://www.tomshardware.co.uk/forum/19797-45-custom-shortcut-keys-list-remove#8344880

Which makes no sense at all (well... at least to me).
Why on earth would windows calculate them at logon?!

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: batch file does not work with shortcut key

#6 Post by foxidrive » 21 Nov 2013 19:38



Thanks for that link.

The solution on that page has issues and fails in later Windows, but I used the info to create a batch file that works to list the hotkeys.

Code: Select all

@echo off
(
echo set WshShell = WScript.CreateObject("WScript.Shell"^)
echo A = Wscript.Arguments(0^)
echo set lnk = WshShell.CreateShortcut(A^)
echo If lnk.hotkey ^<^> "" then wscript.echo lnk.hotkey ^& " - " ^& A
)>"%temp%\findhotkey.vbs"

for %%a in (
"%UserProfile%\desktop"
"%UserProfile%\Start Menu"
"%UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu"
"%Public%\Desktop"
"%AllUsersProfile%\desktop"
"%AllUsersProfile%\Start Menu"
) do (
   cd /d "%%~a" 2>nul && (for /r %%b in (*.lnk *.pif *.url) do cscript /nologo "%temp%\findhotkey.vbs" "%%b")
)

del "%temp%\findhotkey.vbs"
pause   

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: batch file does not work with shortcut key

#7 Post by bars143 » 21 Nov 2013 20:00

foxi,

i used your code in my window-7 32-bit netbook:

result is:

Code: Select all

C:\Users\Jocelyn\AppData\Local\Temp\findhotkey.vbs(4, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'lnk.hotkey'

C:\Users\Jocelyn\AppData\Local\Temp\findhotkey.vbs(4, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'lnk.hotkey'

Press any key to continue . . .


incompatiable to my computer?


-----------------
thanks

bars

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: batch file does not work with shortcut key

#8 Post by foxidrive » 21 Nov 2013 21:10

That's curious. The documentation which supports that .hotkey goes back to Win9x so it should work.

Can someone else test it please?

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: batch file does not work with shortcut key

#9 Post by AiroNG » 22 Nov 2013 03:42

@foxidrive
Test on win7 (64bit). got the same error as bars143.
Test on winXP (32bit, virtual): works perfect.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: batch file does not work with shortcut key

#10 Post by foxidrive » 22 Nov 2013 04:41

Thanks for the tests.

Windows 7 (32 bit) works fine here but...

I've discovered two things - it doesn't support some types of file shortcuts - maybe they were created with a different or older shortcut creation method.

It does still work with the supported links, but each of those unsupported files returns an error like this:

c:\Temp\findhotkey.vbs(5, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'lnk.hotkey'



Another error occurs in my XP VM and it seems that the *.pif should be removed in the FOR loop as this error is returned:

c:\Temp\findhotkey.vbs(3, 1) WshShell.CreateShortcut: The shortcut pathname must end with .lnk or .url.

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: batch file does not work with shortcut key

#11 Post by AiroNG » 23 Nov 2013 19:19

Sadly, i have absolutely no experience with VBscript.
Because of that fact i tried a different approach:
I created some shortcuts (win7 .lnk) to a batch file and gave them different shortcut keys.
then i renamed and opened them with VBinDiff and found what i was looking for:

test1.txt (shortcut: ctrl + alt + i)
0000 0040: 49 06 00 00 00 00 00 00 00 00 00 00 E5 00 14 00 I....... ....Õ...

test2.txt (shortcut: ctrl + alt + p)
0000 0040: 50 06 00 00 00 00 00 00 00 00 00 00 E5 00 14 00 P....... ....Õ...

test3.txt (shortcut: ctrl + shift + p)
0000 0040: 50 03 00 00 00 00 00 00 00 00 00 00 E5 00 14 00 P....... ....Õ...

test4.txt (shortcut: shift + alt + p)
0000 0040: 50 05 00 00 00 00 00 00 00 00 00 00 E5 00 14 00 P....... ....Õ...

test5.txt (shortcut: ctrl + alt + shift + p)
0000 0040: 50 07 00 00 00 00 00 00 00 00 00 00 E5 00 14 00 P....... ....Õ...

IF all shortcut keys would be stored in this manner it could be possible to write a batch-script to search and list them.
To be honest, my knowledge of batch isn't good enough to test that :(

edit:
i posted my solution here: http://www.dostips.com/forum/viewtopic.php?f=3&t=5118

Post Reply