'How do i make a Name Saves and Load when i open the batch file everytime

How do I make a batch file like I type my name, it shows, but when I close it, it disappeared! I need something to save my name so it won't dissappear every time I close and Open the Batch File!

I tried this: echo %text%>> random.dll And I THOUGHT This will Work! And will Always Show Up every time when I close and Open! It didn't work.



Solution 1:[1]

Redirecting the unknown value of %text% to a dll file, which by the way is now simply a plain text file since you wrote plain text to it, will not mysteriously summon your name each time you run a batch-file.

Here are a few ways to do this:

  1. Save the batch-file name as your name for instance Gboy.cmd then use %~n0 which is the name of the file excluding extension.
@echo off
set "myname=%~n0"
echo %myname%
  1. save the name to a file and read it each time:
@echo off
(echo Gboy)>namefile.txt
<namefile.txt set /p myname=
echo %myname%
  1. use setx to save a permanent environment variable. Be careful with this however as you must consider what you create as a variable name and not overwrite any existing system variable:
if not defined myname setx myname gboy && set "myname=gboy"
echo %myname%
  1. it is also quite possible that the name you want to use is already set as your system variable %username% in the required format:
@echo off
echo %username%

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1