8

Is there a way to run/start cmd as administrator through the command line or a batch file programming in Windows 8?

I want to create a batch file which has administrative privileges without any prompt to the user.

3
runas /profile /user:administrator “Driver:\folder\program”

For example, the administrator account is “AAA” and you want to run BBB.exe of C:\programs, you should follow these steps:

  1. Press Win key & R
  2. Input “CMD” in open box and click “OK”
  3. Input: runas /profile /user:AAA “C:\programs\BBB.exe” and press “Enter”
  4. Input the password of administrator AAA
  5. Press “Enter”

Hope it works.

0

You can use runas.exe /savecred /user:administrator cmdor refer this link

0
REM  --> Check for permissions  
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"  

REM --> If error flag set, we do not have admin.  
if '%errorlevel%' NEQ '0' (  
    echo Requesting administrative privileges...  
    goto UACPrompt  
) else ( goto gotAdmin )  

:UACPrompt  
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"  
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    exit /B  

:gotAdmin  
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )   
    pushd "%CD%"  
    CD /D "%~dp0"  
  • 1
    You should put some additional content in this answer explaining what it is doing rather than just proving some back code mixed with VBS and no explanation leaving people that don't know this code scratching their head wondering what it does. I'd look it up and test with it regardless if it was me using it and not understanding it but you get the point. – Pimp Juice IT Jul 18 '17 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.