Cannot get Windows snipping tool to auto run with AutoHotKey

13

2

I am trying to get Windows 7 sniping tool to run when I hit my PRINTSCREEN keyboard button with AUTOHOTKEY.

I have been unsuccessful so far though. Here is what I have for the AutoHotKey script.

I have tried this

PRINTSCREEN::Run, c:\windows\system32\SnippingTool.exe

and this

PRINTSCREEN::Run, SnippingTool.exe

and this

PRINTSCREEN::Run, SnippingTool

And all those give me an error that basically says it cannot find the file, however the file path seems to be correct, I can copy paste it into a window and it opens the snipping tool, any ideas why it will not work?


Here is the full code to my AHK file...

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win7
; Author:         Jason Davis <friendproject@>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


/*
PRINTSCREEN = Will run Windows 7 snipping tool
*/
PRINTSCREEN::Run, c:\windows\system32\SnippingTool.exe
return

JasonDavis

Posted 2010-05-05T00:19:59.057

Reputation: 4 852

Answers

17

Are you running a 64-bit version of Windows 7 by any chance?

Windows 7 (as well as Vista I believe) implements what is called WoW64 Filesystem Redirection. If this is the case, you'll want to point AHK to the Sysnative directory:

PrintScreen::Run, "C:\Windows\Sysnative\SnippingTool.exe"

John T

Posted 2010-05-05T00:19:59.057

Reputation: 149 037

4

Use

PrintScreen::Run C:\Windows\explorer.exe C:\Windows\system32\SnippingTool.exe

This will correctly call the executable withing the boundaries of the WoW64 Filesystem Redirection

Steve

Posted 2010-05-05T00:19:59.057

Reputation: 41

4

You can determine if you need to call SnippingTool.exe from the Sysnative or the windows32 based on whether autohotkey is running as a Wow64 process or not.

PrintScreen::LaunchSnippingTool()

; Determines if we are running a 32 bit program (autohotkey) on 64 bit Windows
IsWow64Process()
{
   hProcess := DllCall("kernel32\GetCurrentProcess")
   ret := DllCall("kernel32\IsWow64Process", "UInt", hProcess, "UInt *", bIsWOW64)
   return ret & bIsWOW64
}

; Launch snipping tool using correct path based on 64 bit or 32 bit Windows
LaunchSnippingTool()
{
    if(IsWow64Process())
    {
        Run, %windir%\Sysnative\SnippingTool.exe
    }
    else
    {
        Run, %windir%\system32\SnippingTool.exe
    }
}

More info and source for IsWow64Process here: http://www.autohotkey.com/community/viewtopic.php?t=22277

jsbannis

Posted 2010-05-05T00:19:59.057

Reputation: 41

I used %A_WinDir% instead of %windir% ,with the #noEnv setting disabled. – jiggunjer – 2016-01-15T06:00:30.483