karthikesh
asked on
Numeric addition in DOS batch files
I would like to generate a sequence
number in a DOS .bat batch file whenever
it is run. So to remember the last count
I want to use a environment (registry)
variable and increment it every time the
batch file is run to get the next sequence
number.
How do I get the value from the registry
variable and how do I change it in my
DOS batch file ?
number in a DOS .bat batch file whenever
it is run. So to remember the last count
I want to use a environment (registry)
variable and increment it every time the
batch file is run to get the next sequence
number.
How do I get the value from the registry
variable and how do I change it in my
DOS batch file ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Uhh,
- there is only ONE line at for /f.... !!
- and one line at reg.exe update .... !!
- remember the tabulator !!
- there is only ONE line at for /f.... !!
- and one line at reg.exe update .... !!
- remember the tabulator !!
ASKER
Hi GBO,
I tried your solution.
I don't have reg.exe but tried with
regedit.exe. Is it OK?
I Created a new Key RCVFNAME under HKEY_LOCAL_MACHINE\SOFTWAR E and a string value COUNT under it. I assigned
a value 1 for COUNT.
And I got the following errors :
Cannot import query: Error opening the
file. There may ne a disk or file
system error.
and
Cannot import HKEY_LOCAL_MACHINE\SOFTWAR E\RCVFNAME \COUNT : Error opening the file. There may be a disk or file system error.
Please reply. Thanks.
I tried your solution.
I don't have reg.exe but tried with
regedit.exe. Is it OK?
I Created a new Key RCVFNAME under HKEY_LOCAL_MACHINE\SOFTWAR
a value 1 for COUNT.
And I got the following errors :
Cannot import query: Error opening the
file. There may ne a disk or file
system error.
and
Cannot import HKEY_LOCAL_MACHINE\SOFTWAR
Please reply. Thanks.
Without a reg tool you'd be best saving the count in file.
First create a file (say count.txt) that contains the required starting sequence number.
Then base your script on the following...
REM path to directory where count file is kept.
cd \count
REM Get value from file...
for /f %%a in ('type count.txt') do set count=%%a
REM Increment count
set /a count=%count%+1
REM Save new count
echo %count%>count.txt
REM Use count....
First create a file (say count.txt) that contains the required starting sequence number.
Then base your script on the following...
REM path to directory where count file is kept.
cd \count
REM Get value from file...
for /f %%a in ('type count.txt') do set count=%%a
REM Increment count
set /a count=%count%+1
REM Save new count
echo %count%>count.txt
REM Use count....
Hi,
you can't use regedit.exe !
Try to download reg.ex http://mspress.microsoft.com/reslink/nt40/toolbox/tools/reg.htm
bye cbo
you can't use regedit.exe !
Try to download reg.ex http://mspress.microsoft.com/reslink/nt40/toolbox/tools/reg.htm
bye cbo
because this is a tricky question I have finished the solution:
I have store the counter at HKLM\SOFTWARE\bob\count. Next I create the following batch. Attention! After "delims=" there is a tabulator and a space ("<tab> ").
You need the reg.exe from the ressource kit to read and wrote to the registry...
--------------------------
@echo off
REM get the value from the registry
for /f "tokens=1-3 delims= " %%a in ('reg.exe query HKEY_LOCAL_MACHINE\SOFTWAR
REM decrement the value
set /A counter=counter+1
REM store the new value to the registry
reg.exe update HKEY_LOCAL_MACHINE\SOFTWAR
REM a test
echo %counter%
pause
--------------------------
How about some points more :-)