Board logo

标题: [注册表类] 批处理如何在注册表中获取软件安装路径? [打印本页]

作者: 15158795291    时间: 前天 13:31     标题: 批处理如何在注册表中获取软件安装路径?

各位大佬,刚学没几天。我想问下,怎么样才能在“不是”管理员权限运行的时候,获取应用程序注册表的安装路径。我这个需要管理员权限,才能获取。
  1. ::查找.exe路径
  2. set "keyPath=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
  3. set "exeName=HC Touch VPro.exe"
  4. set "foundPath="
  5. set "softwarePath="
  6. for /f "tokens=*" %%a in ('reg query "%keyPath%" /s /f "%exeName%" /k 2^>nul') do (
  7.     set "thePath=%%a"
  8.     if "!thePath:~-1!"=="\" set "thePath=!thePath:~0,-1!"
  9.     for /f "tokens=2,*" %%b in ('reg query "!thePath!" /ve 2^>nul') do (
  10. set "type=%%b"
  11. set "value=%%c"
  12. if "!type!"=="REG_SZ" (
  13. set "foundPath=!value!"
  14. goto :endSearch
  15. )
  16.     )
  17. )
  18. :endSearch
  19.     set "softwarePath=!foundPath!"
  20. echo !softwarePath!
复制代码

作者: Batcher    时间: 前天 22:44

回复 1# 15158795291


BAT文件以管理员权限运行有多种方法
http://bbs.bathome.net/thread-49107-1-1.html
作者: ShowCode    时间: 昨天 08:41

回复 1# 15158795291
  1. @echo off
  2. %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("""cmd""","/c """"%~f0"""" ::",,"runas",1)(close) & exit /b
  3. setlocal enabledelayedexpansion
  4. REM 查找.exe路径
  5. set "keyPath=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
  6. set "exeName=HC Touch VPro.exe"
  7. set "foundPath="
  8. set "softwarePath="
  9. for /f "tokens=*" %%a in ('reg query "%keyPath%" /s /f "%exeName%" /k 2^>nul') do (
  10.     set "thePath=%%a"
  11.     if "!thePath:~-1!"=="\" set "thePath=!thePath:~0,-1!"
  12.     for /f "tokens=2,*" %%b in ('reg query "!thePath!" /ve 2^>nul') do (
  13. set "type=%%b"
  14. set "value=%%c"
  15. if "!type!"=="REG_SZ" (
  16. set "foundPath=!value!"
  17. goto :endSearch
  18. )
  19.     )
  20. )
  21. :endSearch
  22. set "softwarePath=!foundPath!"
  23. echo !softwarePath!
  24. pause
复制代码





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