Board logo

标题: [注册表类] 批处理修改注册表,如何为程序添加右键打开菜单? [打印本页]

作者: 3518228042    时间: 2017-5-12 19:48     标题: 批处理修改注册表,如何为程序添加右键打开菜单?

本帖最后由 3518228042 于 2017-5-13 12:07 编辑

批处理修改注册表,如何获取路径添加到注册表,为程序添加右键打开菜单?grepWin.exe可能放在任何位置。
注册表转BAT内容如下:
这个是删除注册表项的
  1. reg delete "HKLM\SOFTWARE\Classes\Directory\shell\grepWin" /f
  2. reg delete "HKCR\*\shell\grepWin" /f
复制代码
下面是需要添加的,但是文件路径没添加进去,需要自动获取文件路径添加进去并且运行。
需要在HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell里面添加grepWin项,并且添加字符串值为grepWin.exe的路径
  1. reg add "HKLM\SOFTWARE\Classes\Directory\shell\grepWin" /f /v "Icon" /t REG_SZ /d "grepWin.exe,-107"
复制代码
需要在HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\grepWin里面添加command项,并且添加字符串值为grepWin.exe的路径
  1. reg add "HKLM\SOFTWARE\Classes\Directory\shell\grepWin\command" /f /ve /t REG_SZ /d "grepWin.exe /searchpath:\"%%1\""
复制代码
需要在HKEY_CLASSES_ROOT\*\shell\里面添加grepWin项,并且添加字符串值为grepWin.exe的路径
  1. reg add "HKCR\*\shell\grepWin" /f /v "Icon" /t REG_SZ /d "grepWin.exe,-107"
复制代码
需要在HKEY_CLASSES_ROOT\*\shell\grepWin里面添加command项,并且添加字符串值为grepWin.exe的路径
  1. reg add "HKCR\*\shell\grepWin\command" /f /ve /t REG_SZ /d "grepWin.exe /searchpath:\"%%1\""
复制代码
也就是说grepWin.exe必须在C:\Windows\System32目录才能运行,
REG_SZ /d "grepWin.exe这个只有程序名称,根本没有路径值,
BAT文件和grepWin.exe文件放在任意目录,运行后路径会添加进去,比如当路径为F:\grepWin\grepWin.exe时候,BAT执行的命令会变成下面的情况
  1. reg add "HKLM\SOFTWARE\Classes\Directory\shell\grepWin" /f /v "Icon" /t REG_SZ /d "F:\grepWin\grepWin.exe,-107"
  2. reg add "HKLM\SOFTWARE\Classes\Directory\shell\grepWin\command" /f /ve /t REG_SZ /d "F:\grepWin\grepWin.exe /searchpath:\"%%1\""
  3. reg add "HKCR\*\shell\grepWin" /f /v "Icon" /t REG_SZ /d "F:\grepWin\grepWin.exe,-107"
  4. reg add "HKCR\*\shell\grepWin\command" /f /ve /t REG_SZ /d "F:\grepWin\grepWin.exe /searchpath:\"%%1\""
复制代码
grepWin.exe论坛下载地址
http://batch-cn.qiniudn.com/tool/grepWin.exe
作者: 3518228042    时间: 2017-5-13 13:56

  1. for /f "delims=" %%a in ('dir /a/s/b/on grepWin.exe') do reg add "HKLM\SOFTWARE\Classes\Directory\shell\grepWin" /f /v "Icon" /t REG_SZ /d ""%%a",-107"
  2. for /f "delims=" %%a in ('dir /a/s/b/on grepWin.exe') do reg add "HKLM\SOFTWARE\Classes\Directory\shell\grepWin\command" /f /ve /t REG_SZ /d ""%%a" /searchpath:\"%%1\""
  3. for /f "delims=" %%a in ('dir /a/s/b/on grepWin.exe') do reg add "HKCR\*\shell\grepWin" /f /v "Icon" /t REG_SZ /d ""%%a",-107"
  4. for /f "delims=" %%a in ('dir /a/s/b/on grepWin.exe') do reg add "HKCR\*\shell\grepWin\command" /f /ve /t REG_SZ /d ""%%a" /searchpath:\"%%1\""
复制代码
运行后添加菜单,在文件或文件夹上鼠标右键能看见grepWin选项,
有没有写得短的?




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2