Autohotkey script to open a command prompt

I have compiled a script from the AutoHotKey forum, which allows me to open the command line in the place where I open in Windows Explorer. If the current window is not an explorer window, the request opens in the place where the script is present. I would like to change this behavior and open it from C:\ if the current window is not an explorer window. I tried to edit the script but did not work as desired.

 #ifwinactive, ahk_class CabinetWClass ControlGetText, address , edit1, ahk_class CabinetWClass if (address <> "") { Run, cmd.exe, %address% } else { Run, cmd.exe, "C:" } ExitApp #ifwinactive 
+5
source share
6 answers

Cmd.exe startup command in c: \

run, cmd.exe, c: \

The full script that will run the cmd window each time will look like this:

 SetTitleMatchMode, 2 ifwinactive, ahk_class CabinetWClass ControlGetText, address , edit1, ahk_class CabinetWClass else address = ; Exclude specific windows ifwinactive, My Computer address = ifwinactive, My Documents address = if (address <> "") Run, cmd.exe, %address% else Run, cmd.exe, C:\ ExitApp 
+8
source

I understand that this is an old question, but I myself studied this and had a better solution.

On Windows, there are two built-in ways to run cmd along the path of the current explorer window. Shift + RightClick, and then click "Open Command Window Here" (or press w). You can also press alt + d, type cmd and press enter. So that...

 LWin & Return:: if WinActive("ahk_class CabinetWClass") or WinActive("ahk_class ExploreWClass") { Send {Shift Down}{AppsKey}{Shift Up} Sleep 10 Send w{enter} } else { run, cmd, C:\ } return 

No magic address capture right from the explorer! :)

+7
source

Here's a pretty complicated script from the AHK forums :

 #NoEnv #SingleInstance Force #NoTrayIcon SendMode Input SetWorkingDir %A_ScriptDir% SetTitleMatchMode RegEx #IfWinActive ahk_class ExploreWClass|CabinetWClass|Progman #c:: WinGetClass WinClass If ( WinClass = "Progman" ) { Run %ComSpec% /K cd /D "C:\" Return } If ( InStr( "WIN_7,WIN_VISTA" , A_OSVersion ) ) { ControlGetText, Path, ToolbarWindow322 RegExMatch(Path, ":\s*(.*)", Path) Path := Path1 } Else { ; Windows XP doesn't know the Edit1 control exists if ; the Address Bar is hidden, so check if it exists and temporarly ; show the Address bar if needed. Temporarly showing the Address bar ; will register the Edit1 control, which contains the path. ControlGetPos Edit1Pos , , , , Edit1 If ( !Edit1Pos ) { PostMessage 0x111 , 41477 , 0 , , A ; Show Address Bar Sleep 100 PostMessage 0x111 , 41477 , 0 , , A ; Hide Address Bar } ControlGetText Path , Edit1 } If ( InStr( Path , ":" ) ) ; If( InStr( Path , ":" ) && FileExist(Path) ) Run %ComSpec% /K cd /D "%Path%" Else Run %ComSpec% /K cd /D "C:\" Return 

I was a little changed part WIN_7 , so that the code does not depend on unreliable control Edit1 , which does not always display the current location of the conductor or wrong. If ( InStr( Path , ":" ) ) ensures that Windows XP does not have the usual path, such as Computer in Windows 7 or My Computer . I also added an alternative condition that additionally checks for the existence of the path if you want to hedge your bets.

+1
source

It was not possible to get other answers to the work (several years have passed since they were written).

I ended up writing this script:

 #o:: Send {Alt down}D{Alt up}cmd{enter} return 
0
source

Keep it simple. Unless, of course, you need complexity.

 !f1:: run, C:\Windows\System32\cmd.exe return 

!f1 means Alt + F1 . According to my personal preferences. Change it to whatever you like.

0
source

Another solution is hacked together from here . It works on Windows 10, but I admit that this is a full copy of the paste. A publication hoping to save someone else from the horror of AHK scripts.

 ;; Open terminal in current Explorer window folder #If WinActive("ahk_class CabinetWClass") ; explorer F4:: WinGetTitle, ActiveTitle, A If InStr(ActiveTitle, "\") ; If the full path is displayed in the title bar (Folder Options) Fullpath := ActiveTitle else If InStr(ActiveTitle, ":") ; If the title displayed is something like "DriveName (C:)" { Fullpath := SubStr(ActiveTitle, -2) Fullpath := SubStr(Fullpath, 1, -1) } else ; If the full path is NOT displayed in the title bar ; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751 for window in ComObjCreate("Shell.Application").Windows { try Fullpath := window.Document.Folder.Self.Path SplitPath, Fullpath, title If (title = ActiveTitle) break } Run, cmd.exe, %Fullpath% return #If 
0
source

Source: https://habr.com/ru/post/1496082/


All Articles