Results 1 to 6 of 6

Thread: Command line script

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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%

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    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

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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
  •  



Click Here to Expand Forum to Full Width