how to elevate a command via cmd.exe

Discussion in 'Windows 8 Help and Support' started by metulburr, Mar 25, 2014.

  1. metulburr

    metulburr Member

    Joined:
    Mar 25, 2014
    Messages:
    5
    Likes Received:
    0
    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>
    
     
    #1 metulburr, Mar 25, 2014
    Last edited: Mar 25, 2014
  2. davidhk129

    davidhk129 Senior Member

    Joined:
    May 19, 2012
    Messages:
    1,337
    Likes Received:
    99
    I sincerely suggest that you ask python experts in python support forums. They can go over your script and check the validity.
     
  3. metulburr

    metulburr Member

    Joined:
    Mar 25, 2014
    Messages:
    5
    Likes Received:
    0
    OK regarding *just* the console then...Why does it say my admin password is wrong even though it is not?
     
  4. davidhk129

    davidhk129 Senior Member

    Joined:
    May 19, 2012
    Messages:
    1,337
    Likes Received:
    99
    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.
     
  5. metulburr

    metulburr Member

    Joined:
    Mar 25, 2014
    Messages:
    5
    Likes Received:
    0
    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.
     
  6. davidhk129

    davidhk129 Senior Member

    Joined:
    May 19, 2012
    Messages:
    1,337
    Likes Received:
    99
    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.
     
  7. metulburr

    metulburr Member

    Joined:
    Mar 25, 2014
    Messages:
    5
    Likes Received:
    0
    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.
     
  8. ussnorway

    ussnorway Windows Forum Team
    Staff Member Premium Supporter

    Joined:
    May 22, 2012
    Messages:
    2,541
    Likes Received:
    318
    Have you checked that the account is enabled?
     

    Attached Files:

  9. metulburr

    metulburr Member

    Joined:
    Mar 25, 2014
    Messages:
    5
    Likes Received:
    0
    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
    
     

Share This Page

Loading...