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

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_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon to 1, but don't know the data type:
call reg_type "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ShutdownWithoutLogon type
if "%type%" EQU "NONE" goto error
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /V ShutdownWithoutLogon /T %type% /F /D 1
REG_Type.bat contains:
@echo off
if \{%3\}==\{\} @echo REG_Type Key ValueName Type&goto :EOF
set type=NONE
set key=%1
set vn=%2
set vx=%vn:"=%
call :quiet>Nul 2>&1
endlocal&set %3=%Type%
goto :EOF
for /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

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.