|
|
本帖最后由 1139054012 于 2025-5-19 23:58 编辑
首先感谢论坛大佬 管理和热心网友多年来帮忙解决很多问题
其他版等级不够,发这里了
参考了@77 @Five66 两位大佬代码,原帖找不到了,忘了关键词
这个注册表文件可以让你在桌面或文件夹空白处点击右键,直接把剪贴板里的文字内容保存成各种类型的文本文件!
比如你复制了一段代码、命令、配置内容,只要点右键选个选项,就能马上生成一个带时间命名的 .txt、.bat、.ps1 或 .reg 文件,省去了新建文件=>复制=>打开文本=>粘贴或者全选删除原来旧代码,再粘贴,再保存步骤, 直接生成带剪切板代码文件,双击直接用和测试就行, 非常方便!
当你右键 → 新建 → 文本文档 / 批处理文件 / PowerShell / 注册表文件时,它会自动生成一个自动用剪贴板的内容替换它(如果剪贴板有文字的话)。 空白内容和文件格式不会创建
乛ᴗ乛经常需要复制粘贴代码的朋友福利功能,比如咱们论坛必用 (复制帖子代码,其他处代码也用得到)
✅ 支持的功能:
在桌面或文件夹空白处右键,会出现这些新选项:
生成txt来自剪贴板 (&T)(ANSI 编码)
生成txt来自剪贴板UTF-8有签名 (&U)(UTF-8 编码,带签名)
生成bat来自剪贴板 (&B) (ANSI 编码)
生成ps1来自剪贴板UTF-8有签名 (UTF-8 编码,带签名)
生成reg来自剪贴板 (&R) (UTF-16 LE 编码)
所有文件都会自动加上当前时间命名,格式是:[240518-123456]new.txt,防止重名。
可以自行修改reg选新建文件默认格式
下载 nircmd.exe
把 nircmd.exe 和 nircmdc.exe 拷贝到 C:\Windows\
双击运行你导入的 .reg 文件
回到桌面或文件夹空白处右键 → 选择你要生成的文件类型即可!
安装- Windows Registry Editor Version 5.00
- ; === 右键菜单:剪贴板生成文件(静默模式+完整时间戳) ===
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt]
- @="生成txt来自剪贴板 (&T)"
- "Icon"="imageres.dll,-5304"
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt\command]
- @="nircmd exec hide powershell.exe -Command "Add-Type -AssemblyName System.Windows.Forms; if ([System.Windows.Forms.Clipboard]::ContainsText()) { $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.txt\\"; $p=Join-Path '%V' $name; if (!(Test-Path $p)) { [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::Default) } }""
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxtutf8]
- @="生成txt来自剪贴板UTF-8有签名 (&U)"
- "Icon"="imageres.dll,-5304"
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxtutf8\command]
- @="nircmd exec hide powershell.exe -Command "Add-Type -AssemblyName System.Windows.Forms; if ([System.Windows.Forms.Clipboard]::ContainsText()) { $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new_utf8.txt\\"; $p=Join-Path '%V' $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::UTF8) }""
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptobat]
- @="生成bat来自剪贴板 (&B)"
- "Icon"="cmd.exe"
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptobat\command]
- @="nircmd exec hide powershell.exe -Command "Add-Type -AssemblyName System.Windows.Forms; if ([System.Windows.Forms.Clipboard]::ContainsText()) { $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.bat\\"; $p=Join-Path '%V' $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::Default) }""
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptops1]
- @="生成ps1来自剪贴板UTF-8有签名 (&P)"
- "Icon"="powershell.exe"
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptops1\command]
- @="nircmd exec hide powershell.exe -Command "Add-Type -AssemblyName System.Windows.Forms; if ([System.Windows.Forms.Clipboard]::ContainsText()) { $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.ps1\\"; $p=Join-Path '%V' $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::UTF8) }""
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptoreg]
- @="生成reg来自剪贴板 (&R)"
- "Icon"="regedit.exe"
- [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptoreg\command]
- @="nircmd exec hide powershell.exe -Command "Add-Type -AssemblyName System.Windows.Forms; if ([System.Windows.Forms.Clipboard]::ContainsText()) { $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.reg\\"; $p=Join-Path '%V' $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::Unicode) }""
- Windows Registry Editor Version 5.00
- [HKEY_CLASSES_ROOT\.txt\ShellNew]
- "ItemName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,\
- 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,\
- 00,6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,2c,00,\
- 2d,00,34,00,37,00,30,00,00,00
- "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"
- [HKEY_CLASSES_ROOT\.bat\ShellNew]
- "ItemName"="新建批处理.bat"
- "Data"=":: 新建批处理文件\n@echo off\necho 此文件由剪贴板内容生成\npause"
- "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"
- [HKEY_CLASSES_ROOT\.ps1\ShellNew]
- "ItemName"="新建PowerShell.ps1"
- "Data"="# 新建PowerShell脚本\nWrite-Host "此文件由剪贴板内容生成"\nRead-Host -Prompt "按任意键继续""
- "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"
- [HKEY_CLASSES_ROOT\.reg\ShellNew]
- "ItemName"="新建注册表.reg"
- "Data"="Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\Software\\新建注册表]"
- "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"
复制代码 为什么不用原来的,经过测试win10专业版,如果复制文件,会导致粘贴失效,所以用PowerShell改了下
1.自动粘贴文本,保留换行格式
2.自动判断剪切板是否文本,空文本和文件不粘贴创建文件,只有剪切板有文本才创建
3.前面加时间,这是我个人习惯,方便判断创建脚本是什么时间的,如果喜欢别的格式,年-月-日-的,可以修改原代码
如果喜欢xxxx/xx/xx日期格式的
因为windows不支持/重命名文件,可以改成2025/05/19,这样就可以重命名成功了
PS: 最近处理字幕问题,多亏一位大佬发的参考代码,学习了不少
发现bat处理一些复杂文本逻辑时,不太方便, 了解PowerShell了强大之处.正则匹配,函数调用,文件格式判断,简繁转换等多年一直想实现功能,但遇到bat的各种疑难杂症只能无奈放弃下 花了几天全部解决了 |
|