[AHK]Win10下将TotalCommander设置为默认文件管理器,即用TC替换资源管理器

将以下脚本存成.ahk扩展名的文件,并运行之(需要ahk环境,请去官网下载安装当前版本Download Current Version )

热键ctrl+win+t   设置TC为默认文件管理器
热键ctrl+win+e   设置资源管理器为默认文件管理器

win+e 启动TC

;Filename:WIN10下设置TC为默认文件管理器(支持恢复Explorer为默认).ahk
;作者:sunwind1576157
;最新版地址:https://blog.csdn.net/liuyukuan/article/details/8493882
;最后更新:2021年9月13日 14时39分
 
;用法:把本脚本放到Totalcmd.exe所在目录,运行之
 
;热键ctrl+win+t 为设置TC为默认文件管理器
;热键ctrl+win+e 为设置资源管理器为默认文件管理器
 
;优点:在TC设置为默认文件管理器时,同时会多一个右键菜单,【OpenWithExplorer】即仍允许用系统的资源管理器打开目录。
 
;功能:WIN7~WIN10下设置TotalCommander为默认文件管理器,即设置TC接管Explorer对计算机中的文件进行管理
;原理:修改注册表,设置文件夹的关联方式。在注册表HKCR\Folder\shell\open\command下。
 
;操作系统:理论支持WIN7到WIN10,本人只在win10上验证
;AutoHotkey版本:需要AutoHotkey v1.1.21+
 
;为了写注册表,需要以管理员权限运行
full_command_line := DllCall("GetCommandLine", "str")
 
;Win10下修改某些注册表需要AutoHotkey在admin权限下运行。
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
 
 
;以下部分设置TC执行文件目录,您也可以简单直接改成自己的tc路径
 
if A_Is64bitOS AND FileExist("Totalcmd64.exe")
	TC=%A_WorkingDir%\Totalcmd64.exe
else if   FileExist("Totalcmd.exe")
	TC=%A_WorkingDir%\Totalcmd.exe
else
	MsgBox 请把本脚本放到Totalcmd.exe所在的目录中,再运行!
 
;设置Win+E启动Tc
#e:: run  %TC%
 
 
;定义热键ctrl+win+t 为设置TC为默认文件管理器
 
^#t::
setTC()
return
;定义热键ctrl+win+e 为设置资源管理器为默认文件管理器
 
^#e::
setExplore()
return
 
 
setTC()
{
	RegRead, IsExp, HKCR\Folder\shell\open\command, DelegateExecute
 	If(IsExp="{11dbb47c-a525-400b-9e80-a54615a090c0}")
	{
		;需要清空DelegateExecute内容,注意不是删除DelegateExecute
		RegWrite, REG_SZ, HKCR\Folder\shell\open\command, DelegateExecute, 
		RegWrite, REG_EXPAND_SZ, HKCR\Folder\shell\open\command, , `"%TC%`" /O /T /L= `"`%1`"
		
		;右键菜单中增加OpenWithExplorer
		RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer, MultiSelectModel, Document
		;~ RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer\command, , `"%SystemRoot%\explorer.exe`" `"`%1`"
		RegWrite, REG_EXPAND_SZ,HKCR\Folder\shell\OpenWithExplorer\command, , `%SystemRoot`%\Explorer.exe `"`%1`"
		RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer\command, DelegateExecute, {11dbb47c-a525-400b-9e80-a54615a090c0}
	}
	MsgBox 已设置TC为默认文件管理器
	return
 
}
 
 
setExplore()
{
	RegWrite, REG_SZ, HKCR\Folder\shell\open\command, DelegateExecute, {11dbb47c-a525-400b-9e80-a54615a090c0}
	RegWrite, REG_EXPAND_SZ, HKCR\Folder\shell\open\command, , `%SystemRoot`%\Explorer.exe
	
	RegDelete HKCR\Folder\shell\openwithExplorer
		
	MsgBox 已恢复Explorer为默认文件管理器
	
}

以下为早期版本,仅供参考研究。

用法:需要把本脚本放到TC目录里,运行第1次切换成TC,再次运行即恢复成Explore资源管理器。

;2019年11月9日 发布第一版

设置TC为默认文件管理器,并且实现用ahk脚本接收操作系统传来的路径,然后用TC打开,并增加自动去重标签功能。

;2020年2月22日 更新,增强控制面板项目兼容性,涉及控制面板的项目会调用Explorer打开。

;Filename:WIN10下设置TC为默认文件管理器(支持恢复Explorer为默认).ahk
;作者:sunwind1576157
;最新版地址:https://blog.csdn.net/liuyukuan/article/details/8493882
;最后更新时间:2020年2月22日19:32:55
;更新内容:增强控制面板项目兼容性,涉及控制面板的项目会调用Explorer打开。
;用法:把本脚本放到Totalcmd.exe所在目录,运行之。运行第一次设置TC为默认,再运行一次恢复Explore为默认,以此类推。
;优点:在TC设置为默认文件管理器时,同时会多一个右键菜单,【OpenWithExplorer】即仍允许用系统的资源管理器打开目录。
;支持标签自动去重,有则激活、无则打开


;功能:WIN7~WIN10下设置TotalCommander为默认文件管理器,即设置TC接管Explorer对计算机中的文件进行管理
;原理:修改注册表,设置文件夹的关联方式。在注册表HKCR\Folder\shell\open\command下。

;操作系统:理论支持WIN7到WIN10,本人只在win10上验证
;AutoHotkey版本:需要AutoHotkey v1.1.21+
SetWorkingDir,%A_ScriptDir%

if NOT FileExist("Totalcmd.exe")
{
	MsgBox 请把本脚本放到Totalcmd.exe所在的目录中,再运行!
	ExitApp
}

If 0 < 1    ;0代表参数个数,该行表示不带参数;注意该处的 if 语句不可加括号
{
		
	full_command_line := DllCall("GetCommandLine", "str")
	;Win10下修改某些注册表需要AutoHotkey在admin权限下运行。
	if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
	{
		try
		{
			if A_IsCompiled
				Run *RunAs "%A_ScriptFullPath%" /restart
			else
				Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
		}
		ExitApp
	}
	;~ MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%
	try{

		RegRead, IsExp, HKCR\Folder\shell\open\command, DelegateExecute

		If(IsExp="{11dbb47c-a525-400b-9e80-a54615a090c0}")
		{
			;需要清空DelegateExecute内容,注意不是删除DelegateExecute
			RegWrite, REG_SZ, HKCR\Folder\shell\open\command, DelegateExecute, 
			;RegWrite, REG_EXPAND_SZ, HKCR\Folder\shell\open\command, ,`"%A_WorkingDir%\Totalcmd.exe`" /O /T /L= `"`%1`"
			RegWrite, REG_EXPAND_SZ, HKCR\Folder\shell\open\command, ,`"%A_AhkPath%`" `"%A_ScriptFullPath%`" `"`%1`"
			
			
			;右键菜单中增加OpenWithExplorer
			RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer, MultiSelectModel, Document
			;~ RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer\command, , `"%SystemRoot%\explorer.exe`" `"`%1`"
			RegWrite, REG_EXPAND_SZ,HKCR\Folder\shell\OpenWithExplorer\command, , `%SystemRoot`%\Explorer.exe `"`%1`"
			RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer\command, DelegateExecute, {11dbb47c-a525-400b-9e80-a54615a090c0}
			
			TrayTip,,切换TotalCommader为默认文件管理器,2000
			Sleep ,1500
			
		}
		else
		{
			RegWrite, REG_SZ, HKCR\Folder\shell\open\command, DelegateExecute, {11dbb47c-a525-400b-9e80-a54615a090c0}
			RegWrite, REG_EXPAND_SZ, HKCR\Folder\shell\open\command, , `%SystemRoot`%\Explorer.exe
		
			RegDelete HKCR\Folder\shell\openwithExplorer
			
			TrayTip,,恢复Explorer为默认文件管理器,2000
			Sleep ,1500
		}

	}
	catch e{
		;~ ; 关于e对象的更多细节, 请参阅 Exception().
		MsgBox, 16,, % "Exception thrown!`n`nwhat: " e.what "`nfile: " e.file
		. "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra . A_LastError
		Exit
	}
}
else
{
	cm_OpenNewTab := 3001
	cm_OpenDirInNewTabOther := 3004
	
	WinGetClass, class, A
	
	
;---------------------------
/*
;~ explorer shell:::{17cd9488-1228-4b2f-88ce-4298e93e0966}  ;默认打开程序
firewall.cpl 

::{26EE0668-A00A-44D7-9371-BEB064C98683}\0\::{4026492F-2F69-46B8-B9BF-5654FC07E423}

*/
;---------------------------
param=%1%
If param not contains ::{,.tib
{
	Run %A_WorkingDir%\Totalcmd.exe /O /T /A /P=R /R=`"%param%`"
}Else{
    ;~ Run % "Explorer.exe " . param
	Run % "explorer shell:" . param
	exitapp
}


	;标签去重并激活到目标目录
	WinWaitActive,ahk_class TTOTAL_CMD ,,2
	PostMessage 1024+51, 3009, 0, , ahk_class TTOTAL_CMD 
	send {Down 12}
	send {Enter}
	
	;再重新在当前标签打开并定位文件(原因是TC默认是关闭了新开的重复标签,历史的文件定位信息丢失)
	Run %A_WorkingDir%\Totalcmd.exe /O /A /P=R /R=`"%1%`"
	
	file:=getFocused()
	;TrayTip,%1% ,来自%class% `n 文件%file%
	;Sleep,5000
}


getFocused()
{
	ControlGet, SelectedItems, List, Focused, SysListView321, ahk_class EVERYTHING
	Loop, Parse, SelectedItems, `n  ; Rows are delimited by linefeeds (`n).
	{
		RowNumber := A_Index
		Loop, Parse, A_LoopField, %A_Tab%  ; Fields (columns) in each row are delimited by tabs (A_Tab).
		{
			;~ MsgBox Row #%RowNumber% Col #%A_Index% is %A_LoopField%.
			if(A_Index=1)
				file:=A_LoopField
			if InStr(A_LoopField,":\")
				dir:=A_LoopField
		}
		;~ return % dir . "\" . file
		return % file
	}
}

以下为早期版本,仅供参考研究。

======================以下《Win10下将TotalCommander设置为默认文件管理器》======================

原理简单:就是修改注册表

;Filename:WIN10下设置TC为默认文件管理器(支持恢复Explorer为默认).ahk
;作者:sunwind1576157
;最新版地址:https://blog.csdn.net/liuyukuan/article/details/8493882
;最后更新时间:2019年11月7日09:27:23

;用法:把本脚本放到Totalcmd.exe所在目录,运行之。运行第一次设置TC为默认,再运行一次恢复Explore为默认,以此类推。
;优点:在TC设置为默认文件管理器时,同时会多一个右键菜单,【OpenWithExplorer】即仍允许用系统的资源管理器打开目录。

;功能:WIN7~WIN10下设置TotalCommander为默认文件管理器,即设置TC接管Explorer对计算机中的文件进行管理
;原理:修改注册表,设置文件夹的关联方式。在注册表HKCR\Folder\shell\open\command下。

;操作系统:理论支持WIN7到WIN10,本人只在win10上验证
;AutoHotkey版本:需要AutoHotkey v1.1.21+
if NOT FileExist("Totalcmd.exe")
{
	MsgBox 请把本脚本放到Totalcmd.exe所在的目录中,再运行!
	ExitApp
}
full_command_line := DllCall("GetCommandLine", "str")

;Win10下修改某些注册表需要AutoHotkey在admin权限下运行。
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
;~ MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%
try{

	RegRead, IsExp, HKCR\Folder\shell\open\command, DelegateExecute

	If(IsExp="{11dbb47c-a525-400b-9e80-a54615a090c0}")
	{
		;需要清空DelegateExecute内容,注意不是删除DelegateExecute
		RegWrite, REG_SZ, HKCR\Folder\shell\open\command, DelegateExecute, 
		RegWrite, REG_EXPAND_SZ, HKCR\Folder\shell\open\command, , `"%A_WorkingDir%\Totalcmd.exe`" /O /T /L= `"`%1`"
		
		;右键菜单中增加OpenWithExplorer
		RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer, MultiSelectModel, Document
		;~ RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer\command, , `"%SystemRoot%\explorer.exe`" `"`%1`"
		RegWrite, REG_EXPAND_SZ,HKCR\Folder\shell\OpenWithExplorer\command, , `%SystemRoot`%\Explorer.exe `"`%1`"
		RegWrite, REG_SZ,HKCR\Folder\shell\OpenWithExplorer\command, DelegateExecute, {11dbb47c-a525-400b-9e80-a54615a090c0}
		
		TrayTip,,切换TotalCommader为默认文件管理器,2000
		Sleep ,1500
		
	}
	else
	{
		RegWrite, REG_SZ, HKCR\Folder\shell\open\command, DelegateExecute, {11dbb47c-a525-400b-9e80-a54615a090c0}
		RegWrite, REG_EXPAND_SZ, HKCR\Folder\shell\open\command, , `%SystemRoot`%\Explorer.exe
	
		RegDelete HKCR\Folder\shell\openwithExplorer
		
		TrayTip,,恢复Explorer为默认文件管理器,2000
		Sleep ,1500
	}

}
catch e{
	;~ ; 关于e对象的更多细节, 请参阅 Exception().
	MsgBox, 16,, % "Exception thrown!`n`nwhat: " e.what "`nfile: " e.file
	. "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra . A_LastError
	Exit
}

======================以下《win7下设置TotalCommander为默认文件管理器》======================

WIN7下请参考流彩的文章:  win7下设置TotalCommander为默认文件管理器 - 夏之日

======================以下《如何将XP系统的资源管理器替换成TC》======================
在DO中有接管WindowsExplorer对计算机中的文件进行管理的选项。TC(TOTALCMD)在启动方面(双击桌面启动、alt tab切换)有些弱,也未提供替换系统Explorer选项。

自己动手丰衣足食!要模仿DO的方式,自己修改注册表来实现TC代替系统的资源管理器。

废话少说,按老习惯上菜,ahk脚本,一共两个脚本,第一个是用来设置用的,只是设置时运行而已,第二个脚本本不用运行,是由系统自动调用的:


 第一个脚本Setup.ahk,设置好下面代码中的Config段运行一次, 替换掉或者取消替换系统的Explorer。

;Filename:Setup.ahk
;操作系统:windows XP

;作者:sunwind(1576157)
;博客:http://blog.csdn.net/liuyukuan

;功能:xp系统下设置TC接管Explorer对计算机中的文件进行管理,本文件主要是修改注册表项,智能处理还需ExplorerHandler指向的ahk文件来处理。

;应用场景:本脚本只是设置用TC打开普通的文件夹;〔我的文档〕〔我的电脑〕〔网上邻居〕〔控制面板〕〔打印机和传真〕


;请用户配置Config中这两项!
Config:
AutoHotkey_path=x:\AutoHotkey\AutoHotkey\AutoHotkey.exe
;用来处理用户所点击文件夹信息的,智能需在ExplorerHandler对应的ahk文件中实现!
ExplorerHandler=X:\short\OpenInTC.ahk 


Main:
regItem=OpenInTC
;引号 百分号 都需要转义符
regValue=`"%AutoHotkey_path%`" `"%ExplorerHandler%`" `"`%1`"
DirectoryShell:=getDirectoryShell(regItem)
Menu, MyMenu, Add,安装(&i)%regItem%,Label_Install
Menu, MyMenu, Add,卸载(&u)%regItem%,Label_UnInstall
Gui, Menu, MyMenu

Gui, Show,w500 h300, 当前DirectoryShell是%DirectoryShell%   ; Show file name in title bar.
return
 
GuiClose:  ; User closed the window.
ExitApp

Label_UnInstall:
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Directory\shell, , none
RegDelete,HKEY_CLASSES_ROOT, Directory\shell\%regItem%
MsgBox 卸载%regItem%完成
gosub,Main
return
Label_Install:
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Directory\shell, ,%regItem%
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Directory\shell\%regItem%, , Open in TotalCommand
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Directory\shell\%regItem%\command, ,%regValue%
MsgBox  安装%regItem%完成

gosub,Main
return

getDirectoryShell(regItem)
{

RegRead, DirectoryShell, HKEY_CLASSES_ROOT, Directory\shell, 
If(DirectoryShell!=regItem)
	SelectedFileName:="Explorer"
else
	SelectedFileName:=DirectoryShell
return %SelectedFileName%
}


 

第二个脚本OpenInTC.ahk,设置好下面代码中的TC的目录,放在该放的位置(比如上面脚本中设置的X:\short\OpenInTC.ahk),文件名也是要符合在上面文件中ExplorerHandler变量中所指定的: 

;Filename:OpenInTC.ahk
;操作系统:windows XP

;作者:sunwind(1576157)
;博客:http://blog.csdn.net/liuyukuan



;功能:xp系统下设置TC接管Explorer对计算机中的文件进行管理,本文件接收到鼠标点击的文件夹,调用相关文件管理器来处理,可自行在此实现智能逻辑(需ahk基础,比如按着某键时才调用TC打开文件夹等等)。
;可以识别已存在标签,不重复打开标签脚本见http://blog.csdn.net/liuyukuan/article/details/8615735

;应用场景:用自己指定的文件管理器打开计算机中的文件夹。

TC:="m:\Total Commander\TOTALCMD.EXE"

Loop, %0%  ;对每个参数执行一次:
{
    param:= %A_Index% 
	if param<>
		Run "%TC%" /O /T /P=L /L="%param%"
	else
		run explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} 
}



 

おすすめ

転載: blog.csdn.net/liuyukuan/article/details/8493882