Atlas-OS / Atlas

🚀 An open and lightweight modification to Windows, designed to optimize performance, privacy and usability.
https://atlasos.net
GNU General Public License v3.0
14.2k stars 528 forks source link

"Run as administrator" doesnt work for batch files with special characters in their names #224

Closed amymor closed 2 years ago

amymor commented 2 years ago

title says it all. as far as i know this bug is related to Microsoft. but it would be great if you fix it in Atlas.

here is the fix script:

Reg.exe add "HKCR\batfile\shell\runas\command" /ve /t REG_EXPAND_SZ /d "%%SystemRoot%%\System32\cmd.exe /C \"\"%%1\" 
Reg.exe add "HKCR\cmdfile\shell\runas\command" /ve /t REG_EXPAND_SZ /d "%%SystemRoot%%\System32\cmd.exe /C \"\"%%1\" %%*\"" /f

just %SystemRoot%\System32\cmd.exe /C "%1" %* changed to %SystemRoot%\System32\cmd.exe /C ""%1" %*"

the only downside is that the working directory will be changed from current to system32 in batch file. but its better than not having access to administrator privileges and also working directory can be set in batch easily, even to make batch programming easier, i created a batch template and placed it in new menu. so my batch always opens in current directory, also it runs itself as administrator by using nsudo. here is my template:

@echo off
:: change dir to current dir
cd /d "%~dp0"
:: checking for administrator privileges
fsutil dirty query %systemdrive% >nul
if %errorlevel% == 0 (goto gotadmin) else (goto E)

:: run itself as administrator 
:E
nsudo -U:E -P:E -UseCurrentConsole "%~0" %*
exit /b

:: got administrator privileges
:gotadmin

:: colorful title for your script
echo  title 

:: do your job here

pause
exit

without explanation:

@echo off
cd /d "%~dp0"
fsutil dirty query %systemdrive% >nul
if %errorlevel% == 0 (goto gotadmin) else (goto E)
:E
nsudo -U:E -P:E -UseCurrentConsole "%~0" %*
exit /b
:gotadmin
echo  title 

pause
exit
Zusier commented 2 years ago

I'm sorry but I don't think I am going to add this due to the problem with the working directory. Any scripts that aren't related to atlas, that also utilize the working directory, will break without that workaround. I just don't see that as a good trade-off, hope you understand.