China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-11 10:28
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Please use reg together with ERRORLEVEL View 954 Replies 10
Original Poster Posted 2009-02-05 17:24 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
★★
Credits 144
Posts 65
Joined 2008-03-20 20:03
18-year member
UID 113522
Gender Male
From Taiwan
Status Offline
Can reg be used together with ERRORLEVEL?
Or is there some other way to achieve what I need

Goal: if the REGISTER value exists then execute, if the value does not exist then exit



for /f "skip=4 tokens=3 delims= " %%i in ('reg query HKCU\Software\Microsoft\Office\11.0\Outlook\Security /v "OutlookSecureTempFolder"') do (set OSTF=%%i)
if errorlevel 0 goto LU

echo Your Outlook Secure TempFolder Path is:
echo "%OSTF%"
echo.
goto end

:LU
echo by~~
goto end

:end

Floor 2 Posted 2009-02-05 17:43 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
if %%i is empty then exit
wouldn't this work?

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 3 Posted 2009-02-05 18:07 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
★★
Credits 144
Posts 65
Joined 2008-03-20 20:03
18-year member
UID 113522
Gender Male
From Taiwan
Status Offline
Originally posted by yishanju at 2009-2-5 05:43 PM:
if %%i is empty then exit
wouldn't this work?

Sir.. I'm not sure whether it works or not ^^"
Because I don't know how to use this command
SORRY~~ = =

Could you give an example, thanks ^^
Floor 4 Posted 2009-02-05 18:14 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
It's right there in if /?

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 5 Posted 2009-02-09 12:02 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
★★
Credits 144
Posts 65
Joined 2008-03-20 20:03
18-year member
UID 113522
Gender Male
From Taiwan
Status Offline
Originally posted by yishanju at 2009-2-5 06:14 PM:
if /? 就有啊


Sir, I'm still not very familiar with using if together with it.
I did read the help, but I'm not very clear on what ERRORLEVEL values REG returns!! ^^


Performs conditional processing in batch programs.

IF ERRORLEVEL number command
IF string1==string2 command
IF EXIST filename command

NOT Specifies that Windows should carry out the command only if
the condition is false.

ERRORLEVEL number Specifies a true condition if the last program run returned
an exit code equal to or greater than the number specified.

string1==string2 Specifies a true condition if the specified text strings
match.

EXIST filename Specifies a true condition if the specified filename
exists.

command Specifies the command to carry out if the condition is
met. Command can be followed by ELSE command which
will execute the command after the ELSE keyword when
the specified condition is false.

The ELSE clause must occur on the same line as the command after the IF. For
example:

IF EXIST filename. (
del filename.
) ELSE (
echo filename. missing.
)

The following would NOT work because the del command needs to be terminated by
a newline:

IF EXIST filename. del filename. ELSE echo filename. missing

Nor would the following work, since the ELSE command must be on the same line
as the end of the IF command:

IF EXIST filename. del filename.
ELSE echo filename. missing

The following would work if you want it all on one line:

IF EXIST filename. (del filename.) ELSE echo filename. missing

If Command Extensions are enabled IF changes as follows:

IF string1 compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command

where compare-op may be one of:

EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal

and the /I switch, if specified, says to do case-insensitive string compares.
The /I switch can also be used on the string1==string2 form of IF. These
comparisons are generic, in that if both string1 and string2 are comprised of
numeric digits only, the strings are converted to numbers and a numeric
comparison is performed.

The CMDEXTVERSION conditional works just like ERRORLEVEL, except it is
comparing against an internal version number associated with the Command
Extensions. The first version is 1. It will be incremented by one when
significant enhancements are added to the Command Extensions. The
CMDEXTVERSION conditional is never true when Command Extensions are disabled.

The DEFINED conditional works just like EXISTS except it takes an environment
variable name and returns true if the environment variable is defined.

%ERRORLEVEL% will expand into a string representation of the current
value of ERRORLEVEL, provided that there is not already an environment
variable with the name ERRORLEVEL, in which case you'll get its value.
After running a program, the following illustrates ERRORLEVEL use:

goto answer %ERRORLEVEL%
:answer0
echo Program had return code 0
:answer1
echo Program had return code 1

You can also use the numerical comparisons above:

IF %ERRORLEVEL% LEQ 1 goto okay

%CMDCMDLINE% will expand into the original command line passed to CMD.EXE
prior to any processing by CMD.EXE, provided that there is not already
an environment variable with the name CMDCMDLINE, in which case you'll
get its value.

%CMDEXTVERSION% will expand into a string representation of the
current value of CMDEXTVERSION, provided that there is not already
an environment variable with the name CMDEXTVERSION, in which case you'll
get its value.

Floor 6 Posted 2009-02-09 13:33 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
reg query "key item" [/v "value"]
echo %errorlevel%
┌───────┐
├→学习→实践→┤
└───────┘
Floor 7 Posted 2009-02-13 14:47 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
★★
Credits 144
Posts 65
Joined 2008-03-20 20:03
18-year member
UID 113522
Gender Male
From Taiwan
Status Offline
Originally posted by wxcute at 2009-2-9 01:33 PM:
reg query "键项"
echo %errorlevel%


Hello
I tested the method you mentioned.
Whether the value exists or not,
the ERRORLEVEL value I get is always 0.
So it seems this won't work.
Is there any other way?
Thanks


cd\
cls
for /f "skip=4 tokens=3 delims= " %%i in ('reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder"') do (set OSTF=%%i)
echo %errorlevel%
pause




C:\>for /F "skip=4 tokens=3 delims= " %i in ('reg query "HKCU\Software\Micro
soft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder"') do (set OSTF=%
i )

Error: The system was unable to find the specified registry key or value.

C:\>echo 0
0

C:\>pause
Press any key to continue . . .




C:\>for /F "skip=4 tokens=3 delims= " %i in ('reg query "HKCU\Software\Micro
soft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder"') do (set OSTF=%
i )

C:\>(set OSTF=C:\Documents and Settings\VM\Local Settings\Temporary Internet Fil
es\OLK64\ )

C:\>echo 0
0

C:\>pause
Press any key to continue . . .
Floor 8 Posted 2009-02-16 15:43 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
★★
Credits 144
Posts 65
Joined 2008-03-20 20:03
18-year member
UID 113522
Gender Male
From Taiwan
Status Offline
It can't be checked inside FOR, maybe I wrote the FOR method wrong ˇˇ
Because it works when it's not under FOR

Content

reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder" >nul
echo %errorlevel%

reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "Outlook" >nul
echo %errorlevel%

pause



Result

C:\>reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "Outlook
SecureTempFolder" 1>nul

C:\>echo 0
0

C:\>reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "Outlook
" 1>nul

Error: The system was unable to find the specified registry key or value.

C:\>echo 1
1

C:\>pause
Press any key to continue . . .


Can someone help modify this?
Thanks!!
Goal: if the REGISTER value exists then execute, if the value does not exist then exit; if the value exists, that value must be set to a variable for later syntax use
Floor 9 Posted 2009-02-16 15:48 ·  美国 华盛顿州 金 雷德蒙德 Microsoft
初级用户
★★
Credits 100
Posts 93
Joined 2009-01-14 15:04
17-year member
UID 136661
Gender Male
From 湖南
Status Offline
The errorlevel value is returned by the system. Why not set an error variable yourself:
1. If it exists, set error=1
2. If it doesn't exist, set error=0
Then immediately follow it with the operation you want to perform. You don't have to get hung up on the system-provided variable %errorlevel%
Floor 10 Posted 2009-02-16 17:31 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
★★
Credits 144
Posts 65
Joined 2008-03-20 20:03
18-year member
UID 113522
Gender Male
From Taiwan
Status Offline
Originally posted by zhengqian529 at 2009-2-16 03:48 PM:
The value of errorlevel is returned by the system. Why not set an error variable yourself:
1. If it exists, set error=1
2. If it doesn't exist, set error=0
Then put the operation you want to execute right after that; you don't necessarily have to get hung up on the system-defined variable %errorlevel%


Mm, thank you!!
Right now I've run into another problem

@echo off
reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder" >nul
if %errorlevel% EQU 0 (

for /f "skip=4 tokens=3 delims= " %%i in ('reg query HKCU\Software\Microsoft\Office\11.0\Outlook\Security /v "OutlookSecureTempFolder"') do (set OSTF=%%i)

echo Your Outlook Secure TempFolder Path is:
echo "%OSTF%"
echo.
) ELSE (
echo Bye!!
)
pause


As long as I add
reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder" >nul
if %errorlevel% EQU 0 (

these two lines, it can no longer detect the path value
The result is as follows

With
reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder" >nul
if %errorlevel% EQU 0 (
result

Your Outlook Secure TempFolder Path is:
""

Press any key to continue . . .


If I add REM to
reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder" >nul
if %errorlevel% EQU 0 (
result

Your Outlook Secure TempFolder Path is:
"C:\Documents and Settings\VM\Local Settings\Temporary Internet Files\OLK64\"

Bye!!
Press any key to continue . . .
Floor 11 Posted 2009-02-18 16:44 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
★★
Credits 144
Posts 65
Joined 2008-03-20 20:03
18-year member
UID 113522
Gender Male
From Taiwan
Status Offline
I couldn't find the cause..
So I had no choice but to rewrite it like this below
Temporarily solved


@echo off
reg query "HKCU\Software\Microsoft\Office\11.0\Outlook\Security" /v "OutlookSecureTempFolder" >nul 2>nul
set OOS=%errorlevel%
for /f "skip=4 tokens=3 delims= " %%i in ('reg query HKCU\Software\Microsoft\Office\11.0\Outlook\Security /v "OutlookSecureTempFolder" 2^>nul') do (set OSTF=%%i)

if %OOS% EQU 0 (
echo.
echo Your Outlook Secure TempFolder Path is:
echo "%OSTF%"
echo.
) ELSE (
echo.
echo Bye!!
echo.
)
pause
Forum Jump: