Reputation: 1
The problem is whenever I'm trying to restart my code with admin rights, it starts with python 3.7. Basically I just want to access admin rights not switching any versions. But according to my arguments and prints that I made, it should be python 3.12, which I currently use. I've tried using pyuac and some others options but it still has same result.
The code:
import win32com.shell.shell as shell
import win32con
shell.ShellExecuteEx(
lpVerb='runas',
lpFile='"' + sys.executable + '"',
nShow=win32con.SW_NORMAL,
lpParameters=' '.join(args)
)
The command that i used:
C:\Users\Username\PycharmProjects\My-project>python3.12 main.py "-startAsAdmin"
Python before restarting:
C:\Users\Username\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\python.exe
Python after restarting:
C:\Users\Username\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe
Upvotes: 0
Views: 65
Reputation: 11
How about omitting using Python from your PATH and instead setting up a virtual environment and using it to execute your code.
This way you would force the interpreter to use a Python version defined by you instead of one of a set of versions stored in the path.
Upvotes: 1