This code is intended for non-administrator users of their computer so that they can run a task / application as admin So i have created an admin user which i would use to launch app ( with path).
I'm getting an issue when i try to launch an app with the command Runas with another user.
The command requires the user's password to be entered
So i have tried to use :
import subprocess as sub
prog = sub.Popen(['runas', '/noprofile', '/user:kairos', path/of/app],shell=True, stdin=sub.PIPE, stdout=sub.PIPE)
prog.communicate(input=password.encode())
But nothing append. Another way was to use the 'Start-Process' Powershell command with credentials
import subprocess as sub
command = """
$username = 'kairos'
$password = 'password'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process "path\to\app" -Credential $credential
"""
exec = sub.Popen(["powershell","& {" + command + "}"], stdout=sub.PIPE)
exec.communicate()
But this command return "Access denied" despite my user is a local admin of the comput
I have also tried to use this command but im stuck with the UAC
ctypes.windll.shell32.ShellExecuteW(None, "runas", "path\to\app")
Any ideas ?