Solved How to run python script as Windows administrator?

December 16, 2014 at 21:35:23
Specs: Windows 7, 8 Gb
I am using python script and win32serviceutil module in order to stop and start Windows services. I am a member of group 'local administrators'. I login as that member and run the script but get the error: Access denied. If I start cmd prompt as Administrator and the run from that window it works fine. My question: how inside the script I could specify to run it as administrator? (note: I don't know administrator password) Thanks

See More: How to run python script as Windows administrator?

Report •


#1
December 17, 2014 at 03:12:45
You don't know the Administrator password, so you can't run the script as Administrator. It would be a horrendous security hole if you could.

But I'm puzzled - if you don't know the Administrator password then how can you start a command prompt as Administrator? And if you can do that, why don't you just use that command prompt to change the Administrator password to one you do know?


Report •

#2
December 17, 2014 at 04:24:48
Well ... since my account is in local admin group I could from Start menu right click on cmd icon and select option 'Run as Administrator'. This starts cmd prompt and all commands are executed "as administrator'
But I need to do this from inside the script

Report •

#3
December 17, 2014 at 18:49:17
✔ Best Answer
I resolved my issue by looking into one of the topics on stackoverflow.com
It suggested to use batch file which will call python script and on the top of that batch use PowerShell command to elevate privilage.
It worked for me.
Ticket could be closed

Report •

Related Solutions


Ask Question