|16 Oct 2010||#1|
| || |
programmatic way with BAT file determining if elevated command prompt
Is there any programmatic way within a BATch file of determining whether it has been started from an elevated command prompt (run as Administrator) or a normal command prompt?
I note the difference between the Current Directory at start of the BATch file, but wonder if there is a better way.
When in elevated mode I don't get a UAC prompt when using DISKPART.
The UAC prompt only happens when running it in a normal command prompt window.
Are you aware of any command which simultaneously would
Last edited by Brink; 16 Oct 2010 at 01:48 PM..
|My System Specs|| |
|17 Oct 2010||#2|
| || |
I can answer my own question, as below
@echo off :: +----------+ :: I Elevated I Test whether this BATch file / Command Prompt :: +----------+ in running in Elevated mode or Normal mode setlocal :: method (applicable to Windows 7, and maybe Vista) :: try to write a zero-byte file to a system directory :: if successful, we are in Elevated mode and delete the file :: if unsuccessful, avoid the "Access is denied" message :: arbitrary choice of system directory and filename set tst="%windir%\$del_me$" :: the first brackets are required to avoid getting the message, :: even though 2 is redirected to nul. no, I don't know why. (type nul>%tst%) 2>nul && (del %tst% & set elev=t) || (set elev=) if defined elev (echo Elevated mode) else (echo Normal mode) endlocal
|My System Specs|
|Similar help and support threads for: programmatic way with BAT file determining if elevated command prompt|
|Elevated Command Prompt Shortcut||Tutorials|
|Elevated Command Prompt||Tutorials|
|Tip for Elevated Command Prompt||General Discussion|
|How to open Elevated Command Prompt?||Performance & Maintenance|
|elevated command prompt fails||General Discussion|