2010-07-09 144 views
7

我有一個批處理腳本,用於檢查註冊表項是否存在,如果存在,則打開Internet Explorer。我現在想要做的是獲取該註冊碼的值並將其放入URL中。我怎樣才能做到這一點?獲取註冊表項的值

@echo off 
reg query HKLM\Software\Test\Monitor\Settings 
if errorlevel 1 goto not_exist 
goto exist 

:not_exist 

:exist 
start "Test" "%ProgramFiles%\Internet Explorer\iexplore.exe" http://localhost:/dashboard.php 

謝謝大家的幫助。

回答

19

在這裏,你應該自我解釋和評論。如果您有任何問題,請告訴我。

@echo off 

set THEME_REGKEY=HKLM\Software\Microsoft\Windows\CurrentVersion\Themes 
set THEME_REGVAL=ThemeName 

REM Check for presence of key first. 
reg query %THEME_REGKEY% /v %THEME_REGVAL% 2>nul || (echo No theme name present! & exit /b 1) 

REM query the value. pipe it through findstr in order to find the matching line that has the value. only grab token 3 and the remainder of the line. %%b is what we are interested in here. 
set THEME_NAME= 
for /f "tokens=2,*" %%a in ('reg query %THEME_REGKEY% /v %THEME_REGVAL% ^| findstr %THEME_REGVAL%') do (
    set THEME_NAME=%%b 
) 

REM Possibly no value set 
if not defined THEME_NAME (echo No theme name present! & exit /b 1) 

REM replace any spaces with + 
set THEME_NAME=%THEME_NAME: =+% 

REM open up the default browser, searching google for the theme name 
start http://www.google.com/search?q=%THEME_NAME% 
+0

謝謝,真的很有幫助! :) – Abs 2010-07-28 11:53:35

+0

@esac REG.EXE'版本和請求的密鑰在WinXP SP3上執行時出現,但腳本工作:) – BalticMusicFan 2014-10-09 19:50:59

+0

做了這樣的事情(reg查詢%THEME_REGKEY%/ v%THEME_REGVAL%2> nul ||(goto :SETUP_001))> nul' – BalticMusicFan 2014-10-09 20:01:39