Discussion:
I need to check if I am running as Administrator
(too old to reply)
T
2022-11-12 05:38:46 UTC
Permalink
Hi All,

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

Many thanks,
-T
JJ
2022-11-12 06:27:20 UTC
Permalink
Post by T
Hi All,
Is there a simple command line I can throw
to tell me if I am running as administrator?
Many thanks,
-T
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
2022-11-12 07:23:48 UTC
Permalink
Post by JJ
Post by T
Hi All,
Is there a simple command line I can throw
to tell me if I am running as administrator?
Many thanks,
-T
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.
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
2022-11-12 07:27:32 UTC
Permalink
Post by T
Post by JJ
Post by T
Hi All,
Is there a simple command line I can throw
to tell me if I am running as administrator?
Many thanks,
-T
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.
Windows 11 pro 22H2
C:\NtUtil>type Windows.RaidCheck.pl6.bat
@echo off
fsutil /? > nul
echo %ERRORLEVEL%
C:\NtUtil>Windows.RaidCheck.pl6.bat
1
This is because
   fsutil /?
   /? is an invalid parameter.
RATS !!!
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
JJ
2022-11-12 12:05:17 UTC
Permalink
Post by T
Post by T
Windows 11 pro 22H2
C:\NtUtil>type Windows.RaidCheck.pl6.bat
@echo off
fsutil /? > nul
echo %ERRORLEVEL%
C:\NtUtil>Windows.RaidCheck.pl6.bat
1
This is because
   fsutil /?
   /? is an invalid parameter.
RATS !!!
Hi JJ,
You put me on the right path though
net sessions & echo %ERRORLEVEL%
System error 5 has occurred.
Access is denied.
2
net sessions & echo %ERRORLEVEL%
There are no entries in the list.
0
Thank you!
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
2022-11-12 22:08:52 UTC
Permalink
Post by JJ
Post by T
Post by T
Windows 11 pro 22H2
C:\NtUtil>type Windows.RaidCheck.pl6.bat
@echo off
fsutil /? > nul
echo %ERRORLEVEL%
C:\NtUtil>Windows.RaidCheck.pl6.bat
1
This is because
   fsutil /?
   /? is an invalid parameter.
RATS !!!
Hi JJ,
You put me on the right path though
net sessions & echo %ERRORLEVEL%
System error 5 has occurred.
Access is denied.
2
net sessions & echo %ERRORLEVEL%
There are no entries in the list.
0
Thank you!
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.
Fancy stuf

Loading...