1.以管理員模式打開CMD
#c::
? ? Run *RunAs cmd
? ? Return
2.在當(dāng)前目錄/文件夾下打開CMD
#c::
? ? dir := getExplorerPath()?
? ? Run, cmd, % dir
? ? Return
getExplorerPath() { ;獲取路徑
? ? If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") {
? ? ? ? WinHWND := WinActive()
? ? ? ? For win in ComObjCreate("Shell.Application").Windows
? ? ? ? ? ? If (win.HWND = WinHWND) {
? ? ? ? ? ? ? ? dir := SubStr(win.LocationURL, 9) ; remove "file:///"
? ? ? ? ? ? ? ? dir := RegExReplace(dir, "%20", " ")
? ? ? ? ? ? ? ? Break
? ? ? ? ? ? }
? ? }
? ? return % dir ? dir : A_Desktop
}
getExplorerPath2(){ ;也是獲取路徑
? ? if WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass"){
? ? ? ? IfWinExist, ahk_class CabinetWClass
? ? ? ? ? ? ControlGetText,address,ToolbarWindow323,ahk_class CabinetWClass
? ? ? ? ? ? StringLen, length, address
? ? ? ? ? ? StringRight, path, address, length-4
? ? ? ? ? ? return path
? ? }
? ? else{
? ? ? ? return A_Desktop
? ? }
}
3.如果是目錄下則在當(dāng)前目錄下打開CMD,否則以管理員模式打開CMD
PS:哪位大神知道怎么實(shí)現(xiàn)以管理員模式在當(dāng)前目錄下打開CMD嗎?
#c::CMD()
CMD() {
? ? If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") {
? ? ? ? WinHWND := WinActive()
? ? ? ? For win in ComObjCreate("Shell.Application").Windows
? ? ? ? ? ? If (win.HWND = WinHWND) {
? ? ? ? ? ? ? ? dir := SubStr(win.LocationURL, 9) ; remove "file:///"
? ? ? ? ? ? ? ? dir := RegExReplace(dir, "%20", " ")
? ? ? ? ? ? ? ? Break
? ? ? ? ? ? }
? ? ? ? Run cmd, % dir
? ? }
? ? else{
? ? ? ? Run *RunAs cmd
? ? }
}