net session >nul 2>&1 || exit
This script runs the net session command, which returns an error message if the user is not an administrator. The || operator allows the script to execute the exit command if the previous command returns an error code. The >nul 2>&1 redirects the output of the net session command to null so that it doesn’t display any error messages on the screen.
Posted on February 4, 2023, 7:47 pm By xuan
Categories: tech tips Tags: admin check, cmd