找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 6149|回复: 3

[文件操作] 【推荐】ClipToFile一个注册表搞定,复制完代码点右键生成各脚本并自动粘贴,省重复步骤

[复制链接]
发表于 2025-5-19 16:32:25 | 显示全部楼层 |阅读模式
本帖最后由 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 文件
回到桌面或文件夹空白处右键 → 选择你要生成的文件类型即可!


安装
  1. Windows Registry Editor Version 5.00

  2. ; === 右键菜单:剪贴板生成文件(静默模式+完整时间戳) ===

  3. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt]
  4. @="生成txt来自剪贴板 (&T)"
  5. "Icon"="imageres.dll,-5304"

  6. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt\command]
  7. @="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) } }""

  8. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxtutf8]
  9. @="生成txt来自剪贴板UTF-8有签名 (&U)"
  10. "Icon"="imageres.dll,-5304"

  11. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxtutf8\command]
  12. @="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) }""

  13. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptobat]
  14. @="生成bat来自剪贴板 (&B)"
  15. "Icon"="cmd.exe"

  16. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptobat\command]
  17. @="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) }""

  18. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptops1]
  19. @="生成ps1来自剪贴板UTF-8有签名 (&P)"
  20. "Icon"="powershell.exe"

  21. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptops1\command]
  22. @="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) }""

  23. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptoreg]
  24. @="生成reg来自剪贴板 (&R)"
  25. "Icon"="regedit.exe"

  26. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptoreg\command]
  27. @="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) }""

  28. Windows Registry Editor Version 5.00

  29. [HKEY_CLASSES_ROOT\.txt\ShellNew]
  30. "ItemName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,\
  31.   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,\
  32.   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,\
  33.   2d,00,34,00,37,00,30,00,00,00
  34. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  35. [HKEY_CLASSES_ROOT\.bat\ShellNew]
  36. "ItemName"="新建批处理.bat"
  37. "Data"=":: 新建批处理文件\n@echo off\necho 此文件由剪贴板内容生成\npause"
  38. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  39. [HKEY_CLASSES_ROOT\.ps1\ShellNew]
  40. "ItemName"="新建PowerShell.ps1"
  41. "Data"="# 新建PowerShell脚本\nWrite-Host "此文件由剪贴板内容生成"\nRead-Host -Prompt "按任意键继续""
  42. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  43. [HKEY_CLASSES_ROOT\.reg\ShellNew]
  44. "ItemName"="新建注册表.reg"
  45. "Data"="Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\Software\\新建注册表]"
  46. "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的各种疑难杂症只能无奈放弃下 花了几天全部解决了
 楼主| 发表于 2025-5-19 23:17:10 | 显示全部楼层
本帖最后由 1139054012 于 2025-5-19 23:24 编辑

原始版本

@77七
  1. Windows Registry Editor Version 5.00

  2. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt]
  3. @="生成txt来自剪贴板(&T)"
  4. "Icon"="imageres.dll,-5304"

  5. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt\command]
  6. @="nircmd exec hide cmd /c nircmd clipboard addfile "新建文本.txt""
复制代码
@Five66
  1. Windows Registry Editor Version 5.00

  2. [HKEY_CLASSES_ROOT\.txt\ShellNew]
  3. "ItemName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,\
  4.   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,\
  5.   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,\
  6.   2d,00,34,00,37,00,30,00,00,00
  7. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" &(nircmd wait 150)& (nircmd shellrefresh)"
  8. ;或者用powershell
  9. ;"Command"="nircmd exec hide powershell -c "nircmd clipboard writefile '%1' (nircmd wait 300) (nircmd shellrefresh)""
复制代码
 楼主| 发表于 2025-5-19 23:30:04 | 显示全部楼层
灵活切换版
✅ 复制文件/剪切板为空时,点击右键一级菜单可以创建空文件,二级新建文件还是必须剪切板有文本才支持创建, 适合切换不同情况需求创建文件,新增html+js
  1. Windows Registry Editor Version 5.00

  2. ; ==== 1. 剪贴板生成 txt 文件(默认编码)====
  3. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt]
  4. @="生成txt来自剪贴板 (&T)"
  5. "Icon"="imageres.dll,-5304"

  6. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxt\command]
  7. @="nircmd exec hide powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -AssemblyName System.Windows.Forms; $path = [System.Net.WebUtility]::UrlDecode('%V'); $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.txt\\"; $p=Join-Path (\\"$path\\") $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::Default)""

  8. ; ==== 2. 剪贴板生成 txt 文件(UTF-8 有签名)====
  9. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxtutf8]
  10. @="生成txt来自剪贴板UTF-8有签名 (&U)"
  11. "Icon"="imageres.dll,-5304"

  12. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptotxtutf8\command]
  13. @="nircmd exec hide powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -AssemblyName System.Windows.Forms; $path = [System.Net.WebUtility]::UrlDecode('%V'); $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new_utf8.txt\\"; $p=Join-Path (\\"$path\\") $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::UTF8)""

  14. ; ==== 3. 剪贴板生成 bat 文件====
  15. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptobat]
  16. @="生成bat来自剪贴板 (&B)"
  17. "Icon"="cmd.exe"

  18. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptobat\command]
  19. @="nircmd exec hide powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -AssemblyName System.Windows.Forms; $path = [System.Net.WebUtility]::UrlDecode('%V'); $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.bat\\"; $p=Join-Path (\\"$path\\") $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::Default)""

  20. ; ==== 4. 剪贴板生成 ps1 文件(UTF-8 有签名)====
  21. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptops1]
  22. @="生成ps1来自剪贴板UTF-8有签名 (&P)"
  23. "Icon"="powershell.exe"

  24. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptops1\command]
  25. @="nircmd exec hide powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -AssemblyName System.Windows.Forms; $path = [System.Net.WebUtility]::UrlDecode('%V'); $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.ps1\\"; $p=Join-Path (\\"$path\\") $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::UTF8)""

  26. ; ==== 5. 剪贴板生成 reg 文件====
  27. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptoreg]
  28. @="生成reg来自剪贴板 (&R)"
  29. "Icon"="regedit.exe"

  30. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptoreg\command]
  31. @="nircmd exec hide powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -AssemblyName System.Windows.Forms; $path = [System.Net.WebUtility]::UrlDecode('%V'); $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.reg\\"; $p=Join-Path (\\"$path\\") $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::Unicode)""

  32. ; ==== 6. 剪贴板生成 js 文件(UTF-8 有签名)====
  33. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptojs]
  34. @="生成js来自剪贴板UTF-8有签名 (&J)"
  35. "Icon"="imageres.dll,-5304"

  36. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptojs\command]
  37. @="nircmd exec hide powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -AssemblyName System.Windows.Forms; $path = [System.Net.WebUtility]::UrlDecode('%V'); $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.js\\"; $p=Join-Path (\\"$path\\") $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::UTF8)""

  38. ; ==== 7. 剪贴板生成 html 文件(UTF-8 有签名)====
  39. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptohtml]
  40. @="生成html来自剪贴板UTF-8有签名 (&H)"
  41. "Icon"="imageres.dll,-5304"

  42. [HKEY_CLASSES_ROOT\Directory\Background\shell\cliptohtml\command]
  43. @="nircmd exec hide powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -AssemblyName System.Windows.Forms; $path = [System.Net.WebUtility]::UrlDecode('%V'); $d=Get-Date -f 'yyMMdd-HHmmss'; $name=\\"[$d]new.html\\"; $p=Join-Path (\\"$path\\") $name; [System.IO.File]::WriteAllText($p, [System.Windows.Forms.Clipboard]::GetText(), [System.Text.Encoding]::UTF8)""

  44. ; === 新建文件模板(ShellNew) ===
  45. ; ShellNew 是“新建”右键菜单中的内容,比如“新建文本文档.txt”

  46. [HKEY_CLASSES_ROOT\.txt\ShellNew]
  47. "ItemName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,\
  48.   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,\
  49.   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,\
  50.   2d,00,34,00,37,00,30,00,00,00
  51. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  52. [HKEY_CLASSES_ROOT\.bat\ShellNew]
  53. "ItemName"="新建批处理.bat"
  54. "Data"=":: 新建批处理文件\n@echo off\necho 此文件由剪贴板内容生成\npause"
  55. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  56. [HKEY_CLASSES_ROOT\.ps1\ShellNew]
  57. "ItemName"="新建PowerShell.ps1"
  58. "Data"="# 新建PowerShell脚本\nWrite-Host "此文件由剪贴板内容生成"\nRead-Host -Prompt "按任意键继续""
  59. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  60. [HKEY_CLASSES_ROOT\.reg\ShellNew]
  61. "ItemName"="新建注册表.reg"
  62. "Data"="Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\Software\\新建注册表]"
  63. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  64. [HKEY_CLASSES_ROOT\.js\ShellNew]
  65. "ItemName"="新建JS.js"
  66. "Data"="// 新建JS文件\nconsole.log("此文件由剪贴板内容生成");"
  67. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"

  68. [HKEY_CLASSES_ROOT\.html\ShellNew]
  69. "ItemName"="新建HTML.html"
  70. "Data"="<!DOCTYPE html>\n<html>\n<head><title>新建HTML</title></head>\n<body>\n<h1>此文件由剪贴板内容生成</h1>\n</body>\n</html>"
  71. "Command"="nircmd exec hide cmd /c nircmd clipboard writefile "%1" & nircmd wait 150 & nircmd shellrefresh"
复制代码
发表于 2025-5-20 16:00:16 | 显示全部楼层
谢谢分享,赞一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 06:00 , Processed in 0.012327 second(s), 7 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表