@echo off rem 使用WMIC获取进程信息中的QQ路径 for /f "tokens=2 delims==" %%a in ('wmic process where "name='qq.exe'" get executablepath /value') do ( set QQPath=%%a ) echo %QQPath%
pause代码:
复制代码 代码如下:
@echo off rem 使用WMIC全盘搜索获取QQ路径 for /f "skip=1 delims=" %%a in ('wmic datafile where "filename='qq' and extension='exe'" get name') do ( set QQPath=%%a ) echo %QQPath%
pause代码:
复制代码 代码如下:
@echo off rem 使用reg命令读注册表获取QQ路径 for /f "tokens=2*" %%a in ('reg query HKEY_LOCAL_MACHINE/Software/Tencent/QQ /v Install^|findstr "Install"') do ( set QQPath=%%b ) echo %QQPath%
pause代码:
复制代码 代码如下:
@echo off rem 使用reg export命令到处注册表项再搜索获取QQ路径以避免reg query可能存在的吃中文字符的问题 reg export "HKEY_LOCAL_MACHINE/SOFTWARE/Tencent/QQ" "%temp%/qq.txt">nul for /f "tokens=2 delims==" %%a in ('type "%temp%/qq.txt"^|findstr /i "Install"') do ( rem 可以用 %%~fa 直接把字符串中的//变成/ set QQPath=%%~a ) set QQPath=%QQPath://=/% echo %QQPath%
pause代码:
复制代码 代码如下:
@echo off rem 调用VBS读注册表获取QQ路径 >"%temp%/my.vbs" echo Set WshShell = WScript.CreateObject("WScript.Shell") >>"%temp%/my.vbs" echo WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE/SOFTWARE/Tencent/QQ/Install") for /f "delims=" %%a in ('cscript /nologo "%temp%/my.vbs"') do ( set QQPath=%%a ) echo %QQPath%