Is there any code to not display the yes/no message (UAC - User Account Control) to run as administrator? How could I do this without having to discover a windows vulnerability? This is very annoying. This is my code to try to adapt:
import pyuac
from pathlib import Path
import shutil
def main():
print("Do stuff here that requires being run as an admin.")
dir_path = Path('C:/Users/RIEIDI~2/AppData/Local/Temp')
for file_path in dir_path.iterdir():
try:
if file_path.is_dir():
shutil.rmtree(file_path)
else:
file_path.unlink()
except OSError:
print(f"Error deleting {file_path}")
input("Press enter to close the window. >")
if __name__ == "__main__":
if not pyuac.isUserAdmin():
print("Re-launching as admin!")
pyuac.runAsAdmin()
else:
main()
So basically, you want a way for your program to elevate its own privileges without the user’s consent, but without finding a vulnerability in Windows?
To further what was already said: If someone did find a way to do this without disabling UAC (which you could do manually if you wanted), it would be considered a vulnerability and point to a security issue with Windows… which I would hope someone would report to Microsoft instead of exploiting.
I was really wondering if there was a script that turned UAC off and after running the script turns it back on well i would do what i need like delete temporary folders measure the size and do other things more sure i would report it if it was a vulnerability
The problem is that if you could have a script that could disable UAC and turn it back on after, then a virus or other malicious application could do the same thing on a similar system, which would make it a vulnerability.
knowing that maybe someone doesn’t pass it on to me for security reasons I have one last question Would you really be able to do this with UAC enabled or do some script that disables and activates later?
Once the process has elevated admin access, you have legitimate options to avoid having to get consent (or OTS credentials if the user isn’t an administrator) in future invocations of your script. You can create either a service or a task that the current user is allowed to start. Once started, the service or task can spawn your script elevated, or as SYSTEM if the user isn’t an administrator. But bypassing UAC from the outset would have to be based on an exploit, which Microsoft would eventually fix.
I understand. but it is for this reason that I would be trying to somehow avoid exploiting some vulnerabilities of windows since they will fix it Well now how antiviruses manage to run hidden as administrator without user permission and that is exactly what I try to do inside my system
unfortunately it doesn’t work anymore I said to see if there were any typos I found out that I have to create and install the service with elevated permissions, it will run as administrator without requiring user interaction or showing UAC.