New
#11
I wrote a bat script example which prompts for admin access and then continues. I hope it helps some... jagaroth: admin access prompt for batch files
After reading this thread I kept going because I didn't want to make a shortcut. I came across a solution that worked well for me and thought I would pass it on. You may put a bit of code at the top of the batch file and it will prompt UAC for admin elevation. The code and explanation of how it works can be found here.
I hope this helps someone as much as it helped me.
@gagruk - Made an account just to thank you bro, saved me tonnes of time searching for this.After reading this thread I kept going because I didn't want to make a shortcut. I came across a solution that worked well for me and thought I would pass it on. You may put a bit of code at the top of the batch file and it will prompt UAC for admin elevation. The code and explanation of how it works can be found here.
I hope this helps someone as much as it helped me.
Hello all,
I present the following batch snippet. It is a one line-er for prompting a UAC dialog box to the user, within a batch file, should the batch script not already be running with Administrative privileges to begin with. And you heard me correctly: ONE. LINE. SOLUTION!
Excuse my excitement, but any batch scripter would know, this is pretty amazingly compact for what it does:
Simply place the above line at the top of your batch script, immediately after "@echo off".Code:net session >NUL 2>&1|| powershell Start-Process '%0' -Verb RunAs&& exit /b|| exit /b
This solution involves no third party tools, no Runas command, no registry lookups/changes, and certainty no temp files. Flawless. It's the real-deal.
Akin to all other techniques found on the Web, this works by making a call to an alternate Windows scripting language that is capable of starting processes with elevated (Administrator) permissions. The reason why the above line of batch script does not require temporary files (and thus only one line in length) is because unlike most other solutions that take advantage of VBScript--which all it's code must be packed into a .vbs file to run--, the solution presented above takes advantage of Windows PowerShell. It is possible to make calls to PowerShell's Cmdlets within batch itself, so no need of generating a temporary script file.
Say "no" to "admin" shortcuts to batch files.
And never disable UAC as a solution!
Last edited by Pyprohly; 24 Jan 2015 at 22:38. Reason: Fixed: Spaces in paths break command line
Sir, I've just created an account to thank you.
I've been looking for this.