Issues
blak3r / Rushyo's solution works fine for everything except Windows 8. Running AT
on Windows 8 results in:
The AT command has been deprecated. Please use schtasks.exe instead.
The request is not supported.
(see screenshot #1) and will return %errorLevel%
1
.
Research
So, I went searching for other commands that require elevated permissions. rationallyparanoid.com had a list of a few, so I ran each command on the two opposite extremes of current Windows OSs (XP and 8) in the hopes of finding a command that would be denied access on both OSs when run with standard permissions.
Eventually, I did find one - NET SESSION
. A true, clean, universal solution that doesn't involve:
- the creation of or interaction with data in secure locations
- analyzing data returned from
FOR
loops
- searching strings for "Administrator"
- using
AT
(Windows 8 incompatible) or WHOAMI
(Windows XP incompatible).
Each of which have their own security, usability, and portability issues.
Testing
I've independently confirmed that this works on:
- Windows XP, x86
- Windows XP, x64
- Windows Vista, x86
- Windows Vista, x64
- Windows 7, x86
- Windows 7, x64
- Windows 8, x86
- Windows 8, x64
- Windows 10 v1909, x64
(see screenshot #2)
Implementation / Usage
So, to use this solution, simply do something like this:
@echo off
goto check_Permissions
:check_Permissions
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
) else (
echo Failure: Current permissions inadequate.
)
pause >nul
Available here, if you're lazy: https://dl.dropbox.com/u/27573003/Distribution/Binaries/check_Permissions.bat
Explanation
NET SESSION
is a standard command used to "manage server computer connections. Used without parameters, [it] displays information about all sessions with the local computer."
So, here's the basic process of my given implementation:
@echo off
- Disable displaying of commands
goto check_Permissions
- Jump to the
:check_Permissions
code block
net session >nul 2>&1
- Run command
- Hide visual output of command by
- Redirecting the standard output (numeric handle 1 /
STDOUT
) stream to nul
- Redirecting the standard error output stream (numeric handle 2 /
STDERR
) to the same destination as numeric handle 1
if %errorLevel% == 0
- If the value of the exit code (
%errorLevel%
) is 0
then this means that no errors have occurred and, therefore, the immediate previous command ran successfully
else
- If the value of the exit code (
%errorLevel%
) is not 0
then this means that errors have occurred and, therefore, the immediate previous command ran unsuccessfully
- The code between the respective parenthesis will be executed depending on which criteria is met
Screenshots
Windows 8 AT
%errorLevel%
:
![[imgur]](https://i.imgur.com/01irE.png)
NET SESSION
on Windows XP x86 - Windows 8 x64:
![[imgur]](https://i.stack.imgur.com/cAAIj.png)
Thank you, @Tilka, for changing your accepted answer to mine. :)
Best Solution
In my experience, no. Whenever a UAC prompt is there you can't run it without administrator rights. You can however try installing it into a flash drive (at home) and if you are lucky enough the game itself might run off of that. UAC blocks most installers, but it doesn't touch quite a lot of actual applications.
HOWEVER, schools tend to have common online game ports blocked, and there's a good chance that even if your game launches it wont connect.