The only distinguisher I have found is that in elevated mode the
default current directory is C:\Windows\system32 whereas for a normal
command prompt the current directory is C:\Users\username...
Someone else posted this style of command to determine if admin is being
used. I think it was diskpart...
set "admin="
diskpart /?>nul&& set admin=1
if defined admin "do something"
--
Regards,
Mic
That would be fine, but DISKPART /? appears to return an errorlevel of
999999999 (yes!).
And in a normal command prompt, you get the UAC prompt.
I can see the principle, but would prefer to find a command which
gives the expected errorlevel and which doesn't pop up a UAC in normal
mode.
The following appears to work successfully in distinguishing whether a
batch file is running in Elevated Mode or in Normal Mode in Windows
7. It has been cribbed from ten.nigriv and modified slightly
:: 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.
:: next command should be on a single line
(type nul>%tst%) 2>nul && (del %tst% & set elev=t) || (set elev=)
if defined elev (echo Elevated mode) else (echo Normal mode)
Mine always comes up as Administrator and I've forgotten how to become
little again, so I can't experiment. Isn't there something in WHOAMI
that indicates the elevation?
Frank