Jump to content

[PS&CMD] My short code line will not work if a folder/file name has an "&" character in it.


Recommended Posts

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 by Outbreaker
Link to comment
Share on other sites


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)

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...