Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I need to check if I am running as Administrator

5 views
Skip to first unread message

T

unread,
Nov 12, 2022, 12:38:47 AM11/12/22
to
Hi All,

Is there a simple command line I can throw
to tell me if I am running as administrator?

Many thanks,
-T

JJ

unread,
Nov 12, 2022, 1:27:43 AM11/12/22
to
You can use: fsutil /?

It'll tell you by a message and ERRORLEVEL=1 if there's no admin rights.

If there's admin rights, it'll simply display fsutil's help and with
ERRORLEVEL=0.

T

unread,
Nov 12, 2022, 2:23:50 AM11/12/22
to
Windows 11 pro 22H2

C:\NtUtil>type Windows.RaidCheck.pl6.bat
@echo off
fsutil /? > nul
echo %ERRORLEVEL%


As an administrator:
C:\NtUtil>Windows.RaidCheck.pl6.bat
1


This is because
fsutil /?
/? is an invalid parameter.

RATS !!!




T

unread,
Nov 12, 2022, 2:27:34 AM11/12/22
to
Hi JJ,

You put me on the right path though

As a user:

net sessions & echo %ERRORLEVEL%
System error 5 has occurred.

Access is denied.

2


As an Administrator:

net sessions & echo %ERRORLEVEL%
There are no entries in the list.

0



Thank you!


JJ

unread,
Nov 12, 2022, 7:05:42 AM11/12/22
to
Whoops. With fsutil, the /? shouldn't be specified. i.e. just `fsutil`
without any command line argument.

Another alternative which is longer to type but not without advantages, is
to simply check the content of the `systemprofile` folder. e.g.

@echo off
if exist %systemroot%\system32\config\systemprofile\* (
echo elevated
) else (
echo not elevated
)

Or try going into that folder...

@echo off
2>nul pushd %systemroot%\system32\config\systemprofile
if errorlevel 1 (
echo not elevated
) else (
popd
echo elevated
)

The advantages of checking that folder is because it's faster than executing
a tool. And a tool may be blocked by group policy, or be excluded by
debloater software from the OS installer to create a minimal OS installation
which is intended to only do specific thing.

T

unread,
Nov 12, 2022, 5:08:55 PM11/12/22
to
Fancy stuff. Thank you.
0 new messages