Batch and registry

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Batch and registry

#1 Post by Adrianvdh » 17 May 2013 16:39

Hello everyone is there a good tutorial on batch registry ... reading, writing and deleting...

Also another question... How could I make a parameter for a batch file...

example
batchfile.bat /p to echo hello

Thanks you so much... :) this is a really great forum :)

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Batch and registry

#2 Post by trebor68 » 18 May 2013 07:43

With REGEDIT will open the registry editor.

With the command REG can you:
reading: REG QUERY /?
writing: REG ADD /?
deleting: RED DELETE /?


Parameters can read.
Test.bat /parameter1 /parameter2=parameter3 parameter4

echo %1
echo %2
echo %3
echo %4

See also SHIFT /?.

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch and registry

#3 Post by Adrianvdh » 18 May 2013 12:38

So could i kinda add a registry item as a varible...
example

for a string

set string=hello

but with the registry how do i contain that reg item and echo the item or store it in a variable? :) thanks again

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Batch and registry

#4 Post by trebor68 » 18 May 2013 13:10

Here a example for reading value from registry.

Code: Select all

@echo off
rem Source: http://technet.microsoft.com/en-us/library/cc978632.aspx

for %%a in (sDate iDate sLongDate sShortDate sTime iTime iTLZero s1159 s2359) do (
  for /f "tokens=2*" %%r in ('REG QUERY "HKCU\Control Panel\International" /v %%a') do (
    set %%a=%%s
  )
)

echo sDate      : "%sDate%"
echo iDate      : "%iDate%"
echo sLongDate  : "%sLongDate%"
echo sShortDate : "%sShortDate%"
echo sTime      : "%sTime%"
echo iTime      : "%iTime%"
echo iTLZero    : "%iTLZero%"
echo s1159      : "%s1159%"
echo s2359      : "%s2359%"
echo.
if %iDate% equ 0 echo short date: mm%sDate%dd%sDate%yy
if %iDate% equ 1 echo short date: dd%sDate%mm%sDate%yy
if %iDate% equ 2 echo short date: yy%sDate%mm%sDate%dd
echo.
if %iTLZero% equ 0 echo Time format:   h%sTime%mm%sTime%ss tt
if %iTLZero% equ 1 echo Time format:  0h%sTime%mm%sTime%ss tt  when single-digit hour
echo The "tt" is value of "s1159" or "s2359"
echo.
if %iTime% equ 0 echo Time with 12-hour clock
if %iTime% equ 1 echo Time with 24-hour clock



See also command FOR.
FOR /F "tokens=2*" %%r in ...
The first token is ignored.
Token number 2 is variable %%r.
Token nummer 3 (any other) is variable %%s. %%s is the next variable after %%r.
In the FOR command are %%r and %%R not the same.

Post Reply