Click here to Skip to main content
15,886,737 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
trying to move file as administrator & bypass the UAC prompt

What I have tried:

echo
if not "%1"=="am_admin" (
powershell -Command "Start-Process -Verb RunAs -FilePath '%0' -ArgumentList 'am_admin'"
exit /b
)

move C:\Users\BDAS\Desktop\hosts*.* C:\Windows\System32\drivers\etc
del %0
Posted
Updated 23-Apr-22 0:58am
v2

You cannot "bypass the UAC prompt" - there would be no security at all if you could do that as the user would not be involved in the promotion.

It's called "User Access Control" for a good reason - the user must consent to the access change.
 
Share this answer
 
You cannot do this in Python (Want to modify hosts file as administrator in Python[^]), Java (Want to move file using core javascript(not node js)[^]), or Powershell (this question) unless you are allowed to run with Administrator privileges. And any attempt to bypass the UAC prompt suggests that this is illegal activity.
 
Share this answer
 
User Access Control, by design, should not be bypassed, otherwise, what's the point of having it in the first place?
There are ways to bypass User Access control. All of them are based on Windows vulnerabilities which are exploited. Thankfully most of them were patched in recent years, but not all of them. The following repo is a serious security set of POCs, published so Microsoft can patch these exploits.

GitHub - hfiref0x/UACME: Defeating Windows User Account Control[^]

I tested method 61 and it worked.
Just compile and open CMD (not as Administrator) and type:
akagi32 61 <your program or batch file that requires Administrator privileges>
 
Share this answer
 
v2
Comments
Dave Kreskowiak 14-Oct-23 18:00pm    
Basing a business process on a hack that can be fixed at any time isn't an answer.
Michael Haephrati 15-Oct-23 7:10am    
I rephrased my answer. Unlike other hacks, bypassing UAC is a real pain. These exploits weren't fixed for many years and some are not expected to be fixed ever because fixing them will interfere with how Windows operates. That being said, these exploits are blocked by most anti viruses and of course by Windows Defender. The information in my answer is provided for educational purposes only.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900