none
get admin right RRS feed

  • Question

  • Hello, 

    I want to lunch a script with admin right but always i have the pop-up message "not the admin right"

    Thx a lot,

    I use this script :

    :::::::::::::::::::::::::::::::::::::::::
    :: Automatically check & get admin rights
    :::::::::::::::::::::::::::::::::::::::::
    @echo off
    CLS
    ECHO.
    ECHO =============================
    ECHO Running Admin shell
    ECHO =============================
    
    :checkPrivileges
    NET FILE 1>NUL 2>NUL
    if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
    
    :getPrivileges
    if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
    ECHO.
    ECHO **************************************
    ECHO Invoking UAC for Privilege Escalation
    ECHO **************************************
    
    setlocal DisableDelayedExpansion
    set "batchPath=%~0"
    setlocal EnableDelayedExpansion
    ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
    ECHO args = "ELEV " >> "%temp%\OEgetPrivileges.vbs"
    ECHO For Each strArg in WScript.Arguments >> "%temp%\OEgetPrivileges.vbs"
    ECHO args = args ^& strArg ^& " "  >> "%temp%\OEgetPrivileges.vbs"
    ECHO Next >> "%temp%\OEgetPrivileges.vbs"
    ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
    "%SystemRoot%\System32\WScript.exe" "%temp%\OEgetPrivileges.vbs" %*
    exit /B
    
    :gotPrivileges
    if '%1'=='ELEV' shift /1
    setlocal & pushd .
    cd /d %~dp0
    
    ::::::::::::::::::::::::::::
    ::START
    ::::::::::::::::::::::::::::
    
    REM Run shell as admin (example) - put here code as you like
    @echo off
    del "c:\scan\*.txt" /F /Q
    cscript.exe "c:\scan\test.vbs"
    ping 127.0.0.1 -n 70 > nul
    move /y c:\folder1\*.txt \\srv\destination
    exit
    

    Thursday, January 21, 2016 4:09 PM

Answers

  • Sorry; I don't understand your statement.

    I tested it and it works fine for me.


    C:\>elevate32 cscript.exe C:\Temp\test.vbs

    This provokes the UAC prompt, and if you click "Yes", the script runs elevated.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bartoch Thursday, January 21, 2016 8:41 PM
    Thursday, January 21, 2016 5:01 PM
    Moderator

All replies

  • My eyes...horrible looking batch/VBScript hybrid...

    This is much easier if you use elevate32.exe/elevate64.exe (http://www.westmesatech.com/misctools.html, ElevationToolkit1.zip).


    C:\>elevate32 C:\Scripts\myscript.cmd


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Thursday, January 21, 2016 4:42 PM
    Thursday, January 21, 2016 4:17 PM
    Moderator
  • I have try that but nothing change, always no right.

    c:\elevate32 cscript.exe "c:\scan\test.vbs"

    Thursday, January 21, 2016 4:45 PM
  • Sorry; I don't understand your statement.

    I tested it and it works fine for me.


    C:\>elevate32 cscript.exe C:\Temp\test.vbs

    This provokes the UAC prompt, and if you click "Yes", the script runs elevated.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bartoch Thursday, January 21, 2016 8:41 PM
    Thursday, January 21, 2016 5:01 PM
    Moderator
  • My eyes...horrible looking batch/VBScript hybrid...

    This is much easier if you use elevate32.exe/elevate64.exe (, ElevationToolkit1.zip).


    C:\>elevate32 C:\Scripts\myscript.cmd


    -- Bill Stewart [Bill_Stewart]

    Perhaps, but that's not always a good approach because you can't count on that resource being there unless you're willing to write in a way to retrieve it as well, such as with PowerShell or some other resource.

    echo powershell -command "(New-Object System.Net.WebClient).DownloadFile('ArbitraryDownloadURL', '$env:APPDATA\stuff.zip')" >> %appdata%\Download_stuff.zip.ps1
    powershell -ExecutionPolicy Bypass -Command "%appdata%\Download_stuff.zip.ps1"

    In this guy's case, the only thing that I see that looks somewhat objectionable is this line, which has an excess space before the >>

    ECHO args = args ^& strArg ^& " "  >> "%temp%\OEgetPrivileges.vbs"

    Everything else seems to check out, and should work.


    • Edited by RDshift Monday, February 26, 2018 8:45 PM
    Monday, February 26, 2018 8:45 PM