2

I follow this script "runas /profile /user:administrator\administrator cmd"and when it prompts me for my password it always says that it is incorrect even though i am spelling it correctly. help please i am trying to write a batch script for school and this is all that is in my way.

Michael
  • 21
  • 1
  • 2
  • 4
    Are you logged in as "administrator"?  *Is your domain name "administrator"?*  When you say `/user:administrator\administrator`, you are specifying that the `cmd` should run as the `administrator` user in the `administrator` domain (which probably doesn't exist), and that is the password it is asking for.  (This isn't `sudo`, where you can become root by typing *your own* password.) – Scott - Слава Україні Apr 17 '15 at 08:30

2 Answers2

2

Like already explained by Wes Sayeed, you aren't able to elevate a running program in Windows. But (even if it's too late four you) here is a solution to restart the command prompt with admin privileges using a kind of embedded VBS:

@echo off

:checkPrivileges
NET FILE 1>NUL 2>NUL

if '%errorlevel%' == '0' (
  goto mainScript 
) else (
  goto getPrivileges
)
::-------------------------------------------------------------------------------------------------

:getPrivileges
  if '%1'=='ELEV' (shift & goto mainScript)
  echo.
  echo Selbstausfuehrung mit Administratorrechten...
  setlocal DisableDelayedExpansion
  set "batchPath=%~0"
  setlocal EnableDelayedExpansion
  echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\runAsAdmin.vbs"
  echo UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\runAsAdmin.vbs"
  "%temp%\runAsAdmin.vbs"
  exit /B
::-------------------------------------------------------------------------------------------------


:mainScript
REM Here we are doing admin stuff...
  cls
  echo Hallo Welt >C:\test.txt
Clijsters
  • 228
  • 2
  • 10
0

The runas command cannot be used to elevate the command prompt -- even if you provide Administrator credentials. There is no way to elevate the command prompt from a non-elevated one.

Wes Sayeed
  • 13,662
  • 6
  • 41
  • 76