I unsuccessfully try to replace a word in a text file with admin rights without the batch file completely reopening.
Here’s an example:
:MENU
cls
echo.
echo MENU (WITHOUT ADMIN RIGHTS)
echo ====================
echo.
echo [1]MAKE SOME STUFF
echo [2]CHANGE SETTING FILE
echo.
echo [0]EXIT
echo.
set asw=0
set /p asw="MAKE YOUR CHOICE: "
if %asw%==1 goto SOMESTUFF
if %asw%==2 goto EDITSETTINGS
if %asw%==0 goto END
:SOMESTUFF
REM EXAMPLE:
md D:test
:EDITSETTINGS
cls
echo.
echo CHANGE SETTING FILE
echo ====================
echo.
echo [1]REPLACE TEXT1
echo [2]REPLACE TEXT2
echo.
echo [0]EXIT
set asw=0
set /p asw="MAKE YOUR CHOICE: "
if %asw%==1 goto REP1
if %asw%==2 goto REP2
if %asw%==0 goto END
:REP1
I WANT TO REPLACE A WORD IN A TEXT FILE LOCATED IN THE PROGRAM FOLDER (WITH ADMIN RIGHTS WITHOUT
UNNING THE BATCH AGAIN, BECAUSE THEN I COME BACK TO THE HOME PAGE)
Example: A File "C:Program Files (x86)Test ProgramName with SpacesText File.txt"
In the text file:
“SomeText
AAAHJHel_lowkk"
I would like to replace the letters "Hel_lo" with "By_e".
:REP2
Here the same thing just with different text...
I hope someone can help me with this…
I’ve tried a few things but haven’t found a solution so that I can run the batch file as non-admin and an admin request only comes when it’s needed and then stays in the same menu item.
New contributor
Marv88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.