Outbreaker Posted May 29, 2022 Posted May 29, 2022 (edited) Hi, I have a short code line that would ask elevated privileges for a Batch file. But now I noticed that if a file name or a folder name has an "&" character in it then the code will not work. 😫 Dose anyone have a solution for this problem? 🤔 @ECHO OFF FLTMC >NUL 2>&1 || PowerShell Start-Process -FilePath '%0' -Verb RunAs >NUL 2>&1 && EXIT /b FLTMC >NUL 2>&1 && GoTo EVD ECHO I'm not wokring. PAUSE :EVD ECHO Hallo World. PAUSE  Edited May 29, 2022 by Outbreaker
jaclaz Posted May 29, 2022 Posted May 29, 2022 You can try with some additional (double) quotes, see here: https://techcommunity.microsoft.com/t5/windows-powershell/batch-file-filename-with-ampersand-amp/m-p/3284432 but cannot say if similar trickery will apply to your case. jaclaz Â
Outbreaker Posted May 29, 2022 Author Posted May 29, 2022 After smashing the web search button for hours, I found a script that works and dose the job better than my previous script. 😃 FLTMC >NUL 2>&1 || Set _=^"Set "_Elevated=1" ^& CD /d """%~dp0""" ^& "%~f0" %*^" && ((If "%Elevated%"=="" ((PowerShell -nop -c START "" CMD -args '/d /x /s /v:off /r',$env:_ -Verb RunAs >NUL 2>NUL) || (MSHTA VBScript:Execute^("CreateObject(""Shell.Application"").ShellExecute(""CMD"",""/d /x /s /v:off /r""&CreateObject(""WScript.Shell"").Environment(""PROCESS"")(""_""),,""RunAs"",1)(Window.Close)"^) >NUL 2>&1))) & EXIT /b) Â
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now