I have following lines in my Batch script which in turn calls Powershell command to self-elevate the batch file as Admin.
@echo off && setlocal
if not "%1"=="admin" (powershell start -verb runas '%0' admin & pause & exit /b)
....
....
But the Batch file path itself and as result the '%0'
contains spaces in the %USERNAME%
(Vivek Shah) especially, and that's why when invoking this script, it throws error:
The term 'C:\Users\Vivek' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
How do I handle spaces in '%0'
and make this script working perfectly ??
Already tried '%~0'
& '"%0"'
but both apparently don't work.