How to run a script without worrying about special characters?

2

I made a batch for windows to install some programs and make settings automatically, it worked normally, but when doing a test using a folder that had space in its name it stopped working, put it in the variable "" and returned to normal .

But I want to avoid any future problems and I made a folder with some characters that can give a problem, the folder name looks like this:

  

New - action folder '; # @ $% ¬ & () + -., {}] [~~~~

This is my last test:

SET mypath="%~dp0"
cd %mypath%

If I opened the cmd by accessing the folder as administrator or with normal user it works normally, but if I use the explore clico twice it works with the normal user but not as administrator, so it opens as administrator the script closes immediately. p>

My script should run as administrator so this has become a problem, of course this problem only occurs in this folder with the full name of special characters.

How to run a script without worrying about special characters?

I've recorded a video for you to see what's going on.

link

    
asked by anonymous 25.09.2017 / 14:46

1 answer

3

I found a unique way to solve your problem. I did my script and it worked out right here but you can choose to do your

you will make a "shell" for your script with the program Bat To Convert EXE I use this technique a lot when I want to compile a script to be able to edit it in the future.

this is the shell script

@echo off
call "script.cmd"

You will compile it with the program and check the "add administrator manifest" option

The shell will have administrative privilege and will then call your script inside.

The script I made was this one.

@echo off
echo.>new_file.txt
ping 0 -n 2 >nul
FOR %%c in (new_file.txt) do (set cam="%%~dpc")
echo.%cam%>dir.txt
pause

setlocal enabledelayedexpansion
for /f "tokens=* delims= " %%F in (dir.txt) do (set linha=%%F
set linha=!linha:"=!
set mypath=!linha!
set mypath=!mypath:^(=^(!
set mypath=!mypath:^)=^)!
set mypath=!mypath:^¬=^¬!

set mypath=!mypath!
echo.!mypath!
cd !mypath!
pause
)
    
14.10.2017 / 15:37