问题
I need to run a file as another user without it prompting for a password, from my script. How is this done?
回答1:
There's an executable program called SANUR.EXE that's made for just this kind of situation: you can use it to pipe in the password on the command-line, like this: runas /user:domain\username cmd.exe | sanur mysekritpassword
.
回答2:
Have the user add whatever it is as a scheduled task with a specific name but no schedule, so it can only be invoked manually. They will need to enter the account credentials when creating the task, but only once. Then you can simply tell schtasks
(Windows command line tool) to run it.
来源:https://stackoverflow.com/questions/4011245/pass-password-to-runas-from-python