metulburr
New Member
- Joined
- Mar 25, 2014
- Messages
- 5
- Thread Author
-
- #1
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:
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
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 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())
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:
Solution
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.
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.
davidhk129
Senior Member
- Joined
- May 19, 2012
- Messages
- 1,315
I sincerely suggest that you ask python experts in python support forums. They can go over your script and check the validity.
davidhk129
Senior Member
- Joined
- May 19, 2012
- Messages
- 1,315
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.
metulburr
New Member
- Joined
- Mar 25, 2014
- Messages
- 5
- Thread Author
-
- #5
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.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 ?
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>
davidhk129
Senior Member
- Joined
- May 19, 2012
- Messages
- 1,315
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.
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.
metulburr
New Member
- Joined
- Mar 25, 2014
- Messages
- 5
- Thread Author
-
- #9
i believe i found a solution to what i was looking for.
a vbs script that elevates my python script
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