I have a script that runs in 2 parts. The first part requires admin access (updates HOSTS file and does some copying/overwriting). After that part finishes, I need to map a drive using the hostname alias the first part of the script updated.
I have figured out how to get the elevated privileges by using this SO Question. But mapping a drive (while in admin) maps a drive into the admin's session. I need to "de-elevate" back into user mode to run my second script.
This is a script I run at least once every day, and possibly multiple times per day. I am trying to create a solution that is just 1 .bat file, if possible. For reasons, the scripts are written in perl.
Things I have tried:
- Using the runas /user:regular_user command (this does not work)
- 1 bat file Using CALL for the 2 batch files (This "works" but for some reason both run at the same time)
- Running 2 bat files separately, and manually.
- Searching SO, but I could not find admin->user instead only user->admin
TLDR: How do I de-elevate to user mode from admin mode in a batch file?