Official admin check for .bat and .cmd files

Discussion in 'Scripting' started by timesurfer, Aug 8, 2011.

  1. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #1 timesurfer, Aug 8, 2011
    Last edited by a moderator: Apr 20, 2017
    Can anyone fathom why someone would have this not work for them

    Example person with difficulties

    Code:
    @color 06
    cls
    mode con: cols=49 lines=12
    md %windir%\TrilogyAdminTest 2>NUL
    if %errorlevel%==0 ( 
    rd %windir%\TrilogyAdminTest 
    goto mainmenu
    ) else (
    echo Right click Trilogy and run as administrator
    echo.
    pause
    goto end
    )
    Thank you
     
  2. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    120
    #2 Josh Cell, Aug 8, 2011
    Last edited by a moderator: Apr 20, 2017
    Try this:

    Code:
    md "%TEMP%\TrilogyAdminTest" >NUL
    IF NOT ERRORLEVEL 1 goto mainmenu
    echo Right click Trilogy and run as administrator
    echo.
    pause
    goto end
    And add this to initial code for mainmenu label

    Code:
    :mainmenu
    rd /S /Q "%TEMP%\TrilogyAdminTest" >NUL
    Please post reports ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #3 timesurfer, Aug 8, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks buddy I will do special Trilogy for this user with difficulties
     
  4. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    120
    The main problem is AV blocking batch changes to %WINDIR% folder...

    My code safest for this is problem :sith:

    Test with you...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    So he has s**tty AV...lol
     
  6. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    120
    #6 Josh Cell, Aug 8, 2011
    Last edited by a moderator: Apr 20, 2017
    Try this is code for new compilation:

    Code:
    @echo off
    @color 06
    cls
    mode con: cols=49 lines=12
    md "%TEMP%\TrilogyAdminTest" >NUL
    IF NOT ERRORLEVEL 1 goto mainmenu
    echo Right click Trilogy and run as administrator
    echo.
    pause
    goto end
    Safest and minimal method...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #7 timesurfer, Aug 8, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Saw my double code did I :sith:

    New dl there is :yoda:

    http://www.datafilehost.com/download-6bd31553.html
     
  8. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    120
    #8 Josh Cell, Aug 9, 2011
    Last edited by a moderator: Apr 20, 2017
    Ok, updating code:

    Code:
    @echo off
    @color 06
    cls
    mode con: cols=49 lines=12
    IF EXIST "%TEMP%\TrilogyAdminTest" rd /S /Q "%TEMP%\TrilogyAdminTest" >NUL
    md "%TEMP%\TrilogyAdminTest" >NUL
    IF ERRORLEVEL 0 goto mainmenu
    echo Right click Trilogy and run as administrator
    echo.
    pause
    goto end
    Works fine on Windows 7 / XP
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #9 timesurfer, Aug 9, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    http://www.datafilehost.com/download-33580f05.html
     
  10. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    It is still unconfirmed as to why he had this problem on two separate OS's?

    And I've only had two reports about this one of which I think users solved on own

    So why rare problem occurs is unknown

    Wait will we for test :yoda:
     
  12. Candlestick

    Candlestick MDL Novice

    Aug 7, 2011
    10
    0
    0
    And patient you must be...


    I havent got the time untill tomorrow.

    BTW Im using Comodo Internet Security. Disabled "Sandbox" and "Defense + Security" but not AV.


    :ninja_hide:
     
  13. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #13 Compo, Aug 9, 2011
    Last edited by a moderator: Apr 20, 2017
    That code is incorrect!

    IF ERRORLEVEL 0 means IF THE ERRORLEVEL IS 0 OR HIGHER, which is always the case.

    You may be better off using this kind of syntax
    Code:
    IF NOT EXIST "%SYSTEMROOT%\TRILOGYADMINTEST" (
    MD "%SYSTEMROOT%\TRILOGYADMINTEST" 2>NUL && (
    RD %SYSTEMROOT%\TRILOGYADMINTEST
    ) || (
    ECHO=Right click %~nx0 and Run as administrator.
    ECHO=
    ECHO=Press any key to Exit.
    PAUSE>NUL
    GOTO end
    )
     
  14. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    120
    #14 Josh Cell, Aug 9, 2011
    Last edited by a moderator: Apr 20, 2017
    lol, The ERRORLEVEL 0 it's NO-ERRORS Return code for latest command

    If the folder is created with success, ERRORLEVEL = 0

    If occur any error of the creation, the ERRORLEVEL is NOT = 0, validating the code .
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    Since I got your guys attention lets take this to Trilogy thread

    Thank you JC and compo
     
  16. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    You are mistaking ERRORLEVEL with %ERRORLEVEL%, IF ERRORLEVEL 0 means if the Error Level is at least 0, which is true of ERRORLEVEL 0, ERRORLEVEL 1, ERRORLEVEL 2 etc.

    If your folder is created without success, i.e. not created, then an Error level of 1 OR More may be returned, they would howecver still be validated by that line.

    In your case you should have validated by using IF NOT ERRORLEVEL 1, that would have been true for anything other than an Error Level of 0, which was your goal.
     
  17. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    Still not working either of persons code
     
  18. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #18 Compo, Aug 9, 2011
    Last edited by a moderator: Apr 20, 2017
    I wasn't trying to fix the random error your users were having, I was simply correcting the error in the information with which you were provided.

    Have you thought about changing the method of checking for Elevation to using the registry instead of writing a file? You could try something like this:
    Code:
    REG QUERY "HKU\S-1-5-19" >NUL 2>&1 && (
    GOTO NEXT
    ) || (
    ECHO=Right click %~nx0 and Run as administrator.
    ECHO=
    ECHO=Press any key to Exit.
    PAUSE>NUL
    GOTO end
    )
     
  19. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #19 timesurfer, Aug 9, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I understand you wern't that is why I suggested going to trinity thread where I explained it more and posts also ;)

    Thank you so much for your help compo

    I hadn't thought of that am waiting on candlestick in Trilogy thread to confirm my last post code is working

    Works for me :D

    Please go there :biggrin:

    Also check this post out http://forums.mydigitallife.net/threads/28566-Creating-task-in-batch-with-multiple-triggers

    Thanks
     
  20. Tr3bg0D

    Tr3bg0D MDL Junior Member

    May 8, 2011
    94
    3
    0
    #20 Tr3bg0D, Aug 9, 2011
    Last edited by a moderator: Apr 20, 2017
    R U saying of the KEY does not exist you do not have administrative privilege?