标题: [注册表类] 批处理如何在注册表中获取软件安装路径? [打印本页]
作者: 15158795291 时间: 前天 13:31 标题: 批处理如何在注册表中获取软件安装路径?
各位大佬,刚学没几天。我想问下,怎么样才能在“不是”管理员权限运行的时候,获取应用程序注册表的安装路径。我这个需要管理员权限,才能获取。- ::查找.exe路径
- set "keyPath=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
- set "exeName=HC Touch VPro.exe"
- set "foundPath="
- set "softwarePath="
- for /f "tokens=*" %%a in ('reg query "%keyPath%" /s /f "%exeName%" /k 2^>nul') do (
- set "thePath=%%a"
- if "!thePath:~-1!"=="\" set "thePath=!thePath:~0,-1!"
- for /f "tokens=2,*" %%b in ('reg query "!thePath!" /ve 2^>nul') do (
- set "type=%%b"
- set "value=%%c"
- if "!type!"=="REG_SZ" (
- set "foundPath=!value!"
- goto :endSearch
- )
- )
- )
- :endSearch
- set "softwarePath=!foundPath!"
- echo !softwarePath!
复制代码
作者: Batcher 时间: 前天 22:44
回复 1# 15158795291
BAT文件以管理员权限运行有多种方法
http://bbs.bathome.net/thread-49107-1-1.html
作者: ShowCode 时间: 昨天 08:41
回复 1# 15158795291 - @echo off
- %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("""cmd""","/c """"%~f0"""" ::",,"runas",1)(close) & exit /b
-
- setlocal enabledelayedexpansion
- REM 查找.exe路径
- set "keyPath=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
- set "exeName=HC Touch VPro.exe"
- set "foundPath="
- set "softwarePath="
- for /f "tokens=*" %%a in ('reg query "%keyPath%" /s /f "%exeName%" /k 2^>nul') do (
- set "thePath=%%a"
- if "!thePath:~-1!"=="\" set "thePath=!thePath:~0,-1!"
- for /f "tokens=2,*" %%b in ('reg query "!thePath!" /ve 2^>nul') do (
- set "type=%%b"
- set "value=%%c"
- if "!type!"=="REG_SZ" (
- set "foundPath=!value!"
- goto :endSearch
- )
- )
- )
-
- :endSearch
- set "softwarePath=!foundPath!"
- echo !softwarePath!
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |