Been fighting with a batch script here. What I'm trying to do is use a variable that was input within an if statement (device_name) and have it save the returned value in the file so it only runs the first time it is loaded. I have it kind of working with the :InitFirstRun as the code kinda over writes the line if I don't use user input.
What I want to happen: First time batch is run it will prompt user to enter their ID, it will then save as a persistent variable device_name, as they won't be able to change it after I'd like to confirm entry with response.
Where the problem is currently lying is it will not update device_name within the if statement - when echo Is device_name is called within the if statement it returns 'First'. If I call device_name after the if statement it returns the entered value.
I'm wondering how I could do this. Open to any and all suggestions on all aspects of this as I'm totally stumped.
I have frankenstined persistent variable from this: How do I have a persistent variable in batch?
Having a separate 'pref' file is not feasible as it needs to be self contained in one file.
call :InitFirstRun
if %device_name%==First (
echo This is the first time you are launching this app.
echo.
echo Enter your ID below.
set /p device_name="Enter ID: "
echo.
echo Is %device_name% correct?
set /p response=Enter y or n:
if /I %response%==y (
echo Your device has been saved as %device_name%
echo %device_name% >> "%~F0"
)
if /I %response%==n (
need to find a way to loop back to set /p "device_name=Enter ID"
or I just quit the app with no saving and they have to load again?
)
) else (
echo Your station and Device are set as: %device_name%
)
:InitFirstRun
set device_name=First