JSI Tip 9060. How can I use REG.EXE to set a data value without knowing the exact data type?

Jerold Schulman

February 15, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted REG_Type.bat to return the data type of a specified Key and Value Name.

The syntax for using REG_Type.bat is:

call REG_Type Key ValueName Type

Where Key is a any valid key, using REG.EXE format, ValueName is a Value Name at Key, and Type is a call directed environment variable that will contain the data type of ValueName, or NONE if the ValueName is NOT found.

Sample Usage:

If you want to set ShutdownWithoutLogon at HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogon to 1, but don't know the data type:

call reg_type "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogon" ShutdownWithoutLogon typeif "%type%" EQU "NONE" goto errorreg add "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogon" /V ShutdownWithoutLogon /T %type% /F /D 1

REG_Type.bat contains:

@echo offif {%3}=={} @echo REG_Type Key ValueName Type&goto :EOFsetlocal ENABLEDELAYEDEXPANSIONset type=NONEset key=%1set vn=%2set vx=%vn:"=%call :quiet>Nul 2>&1endlocal&set %3=%Type%goto :EOF:quietfor /f "Tokens=*" %%a in ('reg query %key% /V %vn%^|FIND "REG_"') do ( set work=%%a set work=!work:%vx%=! set work=!work:*REG_=REG_! for /f "Tokens=1" %%b in ('@echo !work!') do (  set type=%%b ))



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like