yori: If ErrorLevel / Is Yori Elevated ?
Hello… I’m new to Yori… I’m enjoying its simplicity, useful completions, and (thank you for) the aliases. But I do have some pretty basic issues:
- Is there a way to use ERRORLEVEL within an IF statement?..
And:
- Is there a way to determine from a .ys1 script (Init file) if the current shell is running with elevation?
I usually do this in CMD by running any command that requires elevation, which sets the ErrorLevel… for example:
$ net session>nul 2>&1
$ if ErrorLevel == 0 (Echo We have elevation)
But in a Yori script (Init file) it seems neither if statements, nor the ErrorLevel can be used (conditionally) at all… Even calling an external script .cmd for this task seems not to work… Or is there currently a way to do it?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (9 by maintainers)
Firstly, that’s a really nice prompt! As you’ve probably seen, the default includes
$G_OR_ADMIN_G$which is not as visually impressive but is still attempting to convey the same information.Ifhas been a bit painful because the CMD grammar for it is so inconsistent. It’s one area where Yori does something very different to CMD, and is much closer to bash. Each test is invoking a child program of some kind. Errorlevel is accessible via%ERRORLEVEL%. So something like this should work:Yori also includes a command whose intended purpose is to answer the question of whether the user is elevated:
grpcmp.Note the second case is indicating an admin prompt via the prompt char.