Two scripts with the same results, but require different permissions WHY?

Discussion in 'Scripting' started by avi smile, Jun 29, 2016.

  1. avi smile

    avi smile MDL Junior Member

    Mar 1, 2015
    98
    58
    10
    #1 avi smile, Jun 29, 2016
    Last edited by a moderator: Apr 20, 2017
    Hi there.

    I wrote for myself a small script, that checks the activation status of the installed MS Office products, but i ran into trouble, for some reason i kept on getting "'cscript' is not recognized as an internal or external command, operable program or batch file.", i figured out that the problem was that it needed admin privilege, but in the meantime i had already created another batch to get to the same results just via a different way, and it worked without Admin privilege, why did the first one require admin privilege and the second one did not?

    First batch file (requires admin)
    Code:
    :10-32
    if not exist "C:\Program Files (x86)\Microsoft Office\Office14" (
        goto :10-64
        ) else (
        set "path=C:\Program Files (x86)\Microsoft Office\Office14"
        )
        goto :run
    
    
    :10-64
    if not exist "C:\Program Files\Microsoft Office\Office14" (
        goto :13-32
        ) else (
        set "path=C:\Program Files\Microsoft Office\Office14"
        )
        goto :run
        
    :13-32
    if not exist "C:\Program Files (x86)\Microsoft Office\Office15" (
        goto :13-64
        ) else (
        set "path=C:\Program Files (x86)\Microsoft Office\Office15"
        )
        goto :run
    
    
        
    :13-64
    if not exist "C:\Program Files\Microsoft Office\Office15" (
        goto :16-32
        ) else (
        set "path=C:\Program Files\Microsoft Office\Office15"
        )
        goto :run
        
    :16-32
    if not exist "C:\Program Files (x86)\Microsoft Office\Office16" (
        goto :16-64
        ) else (
        set "path=C:\Program Files (x86)\Microsoft Office\Office16"
        )
        goto :run
    
    
        
    :16-64
    if not exist "C:\Program Files\Microsoft Office\Office16" (
        echo there is no office installed on this system
        ) else (
        set "path=C:\Program Files\Microsoft Office\Office16"
        )
        goto :run
    
    
    :run
    cscript "%path%"\ospp.vbs /dstatus
    pause
    
    Second batch script (does not require admin)
    Code:
    :10-32
    cscript "C:\Program Files (x86)\Microsoft Office\Office14"\ospp.vbs /dstatus
        if errorlevel 1 (
        cls
        goto :10-64
        )
        pause
    
    
    :10-64
    cscript "C:\Program Files\Microsoft Office\Office14"\ospp.vbs /dstatus
        if errorlevel 1 (
        cls
        goto :13-32
        )
        pause
        
    :13-32
    cscript "C:\Program Files (x86)\Microsoft Office\Office15"\ospp.vbs /dstatus
        if errorlevel 1 (
        cls
        goto :13-64
        )
        pause
        
    :13-64
    cscript "C:\Program Files\Microsoft Office\Office15"\ospp.vbs /dstatus
        if errorlevel 1 (
        cls
        goto :16-32
        )
        pause
        
    :16-32
    cscript "C:\Program Files (x86)\Microsoft Office\Office16"\ospp.vbs /dstatus
        if errorlevel 1 (
        cls
        goto :16-64
        )
        pause
        
    :16-64
    cscript "C:\Program Files\Microsoft Office\Office16"\ospp.vbs /dstatus
        if errorlevel 1 goto :eof
    
        pause
    
    Whats even more weird, "cscript" doesn't usually need admin rights :confused:.

    Thanks in advance
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    What happens if you set the name of your variable in the first script something other than an existing environment variable?
     
  3. avi smile

    avi smile MDL Junior Member

    Mar 1, 2015
    98
    58
    10
    Wow so simple!, i didn't know that %path% was a system environment variable.

    Thanks millions!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...