|
-
May 6th, 2003, 06:33 PM
#1
Thread Starter
Frenzied Member
Command line script
Can anyone help me with this script...
REM Check if this has been run before
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v Status
IF ERRORLEVEL 1 GOTO update ELSE GOTO quit
REM Do this if this is first run
:update
REM update and save result to logfile
reg.exe import test.reg >> %COMPUTERNAME%.txt
IF ERRORLEVEL 1 GOTO faulty ELSE GOTO quit_ok
:faulty
echo ERROR! >> %COMPUTERNAME%.txt
goto quit
:quit_ok
echo Update complete! >> %COMPUTERNAME%.txt
:quit
echo bye >> %COMPUTERNAME%.txt
for now it is very basic, all it does is that it set a flag to prevent the test.reg file to be uploaded more than once and write some output to a logfile. But the problem is that EVERYTHING is performed, the IF's doesn't seem to be working. ANyone that has any clues????
kind regards
Henrik
-
May 7th, 2003, 04:20 AM
#2
I've never seen Else's in a batch file before, are you sure they work?
I've always seen this kind of thing:
IF ERRORLEVEL 1 GOTO update
GOTO quit
Also, check the value of ErrorLevel before each IF, it might not have the value you expect
-
May 7th, 2003, 07:39 AM
#3
Thread Starter
Frenzied Member
well if you type if /? on the command line and browse a few pages down you will see an example with else...?!?
Also how can I check the errorlevel? I am a bit of a newbie when it comes to command line scripting
thanks
Henrik
-
May 7th, 2003, 08:42 AM
#4
I haven't used command line scripting for years (as with most people!), but i'd guess that it would be:
echo ERRORLEVEL
or:
echo %ERRORLEVEL%
-
May 7th, 2003, 04:25 PM
#5
Thread Starter
Frenzied Member
Yes I have confirmed that errorlevel is correct! But I still have no clue why it doesn't obey the if's and else's. Can someone provide a solution without the elses? I think it will be too many gotos then, but what the heck... I thought this would be simple *grin*...
Actually the only reason I didn't make a vb program (that could do all this with ease) is that the customer didn't want any dependences like dlls or ocx's...
best regards
Henrik
-
May 8th, 2003, 06:55 AM
#6
try this:
REM Check if this has been run before
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v Status
IF ERRORLEVEL 1 GOTO update
GOTO quit
REM Do this if this is first run
:update
REM update and save result to logfile
reg.exe import test.reg >> %COMPUTERNAME%.txt
IF ERRORLEVEL 1 GOTO faulty
echo Update complete! >> %COMPUTERNAME%.txt
goto quit
:faulty
echo ERROR! >> %COMPUTERNAME%.txt
:quit
echo bye >> %COMPUTERNAME%.txt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|