Windows 8 how to elevate a command via cmd.exe

metulburr

Member
I am trying to elevate a command given (in this case just another cmd.exe) if the user is not admin. However i get the error:

Code:
C:\Users\metul_000>runas /user:administrator cmd.exe
Enter the password for administrator:
Attempting to start cmd.exe as user "WINDOWS8\administrator" ...
RUNAS ERROR: Unable to run - cmd.exe
1326: The user name or password is incorrect.

C:\Users\metul_000>

this is a personal pc, and i know i put in the password correctly as i have done it a few times slowly typing in my admin password to confirm that it is input correctly. So why am i getting this error?

initially my overall goal is to get this python script to say you are admin
Code:
import ctypes
import subprocess
import sys
import os

if os.name == 'nt':
    if ctypes.windll.shell32.IsUserAnAdmin():
        print('You are admin')
    else:
        print('You are not admin')
        print('running as admin')
        command = 'python3 {}'.format(sys.argv[0])
        cmd = 'runas /user:administrator "{}"'.format(command)
        subprocess.call(cmd.split())
if you are admin its done, but if you are not admin then it reruns itself with the so called runas command to get admin rights. However currently it just pulls up the runas usage messages. The full command this script attempts to run then is:
Code:
C:\Users\metul_000>runas /user:administrator "python3 test2.py"
Enter the password for administrator:
Attempting to start python3 test2.py as user "WINDOWS8\administrator" ...
RUNAS ERROR: Unable to run - python3 test2.py
1326: The user name or password is incorrect.

C:\Users\metul_000>
 
Last edited:
I sincerely suggest that you ask python experts in python support forums. They can go over your script and check the validity.
 
OK regarding *just* the console then...Why does it say my admin password is wrong even though it is not?

I am not a python programmer. Last time I learnt computer programming was Basic Language and that was 30 years ago.

What if you exit the python application, sign in to a regular user account.
Open cmd and select Run As Admin > are you asked for admin password ? If yes, enter it. Does it accept the password ?
If it does, then your python script is faulty at the beginning.

I stop here before I put my foot into my mouth.
 
What if you exit the python application, sign in to a regular user account.
Open cmd and select Run As Admin > are you asked for admin password ? If yes, enter it. Does it accept the password ?
That is what i am saying. Forget the python script. The first and last code snippets of the OP are not ran from python, it is ran from windows command line. I only put the python script for completeness. I am not just trying to get the console to run as admin, i am trying to re-run the script as admin if the user is not admin. The easiest way to do that in python is via command line, but this command line "runas" does not work.

OK forget 100% about python...in the command console if i enter...i get the error:
Code:
C:\Users\metul_000>runas /user:administrator cmd.exe
Enter the password for administrator:
Attempting to start cmd.exe as user "WINDOWS8\administrator" ...
RUNAS ERROR: Unable to run - cmd.exe
1326: The user name or password is incorrect.

C:\Users\metul_000>
Why does it say my password or username is not correct, because it is.
 
I can only offer troubleshooting suggestions :

1. Logon to you admin account > make sure you can run elevated cmd.
If no, it does not work, I am out of idea except re-installing Win 8.
If yes, it does work, go to #2.
2. Create a new user account ( non-admin ) > sign in to it > try the elevated cmd again. Does it work this time ?
If yes it does work, then your other user account is corrupted.
If no, it does not work, go to #3.
3. Logon to your admin account and do a system file check looking for corrupt files. It will try to do repair if any found.
I am confident that you know how to do sfc /scannow. If not please post back.
 
i can get admin rights with the command prompt, but i have to use GUI to do it. I want a command line method to do the same.
 
Have you checked that the account is enabled?
 

Attachments

  • admin.png
    admin.png
    139 KB · Views: 503
i believe i found a solution to what i was looking for.
a vbs script that elevates my python script
Code:
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "C:\Python27\python", "C:\Users\metul_000\test2.py", "", "runas", 1
 
Back
Top