I want to create the command hello without having to create a file like hello.bat. I want the command without the file. The command must execute an echo Hello World!.
Is there a way to do it on Windows?
You can use doskey
.
Open a cmd shell
Enter the following command:
doskey hello=echo Hello world!
Run the command:
hello
Example:
F:\test>doskey hello=echo Hello world!
F:\test>hello
Hello world!
F:\test>
enter image description here
which makes them somewhat opaque to screen reader software
In command line:
Using setx
command:
rem :: For current user (save in "HKEY_CURRENT_USER")
setx Hello "echo Hello world!"
rem :: For all users (save in "HKEY_LOCAL_MACHINE")
setx Hello "echo Hello world!" /m
Using reg add
command:
rem :: For current user (save in "HKEY_CURRENT_USER")
reg add HKCU\Environment /v Hello /d "echo Hello world!" /f
rem :: For all users (save in "HKEY_LOCAL_MACHINE")
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Hello /d "echo Hello world!" /f
For current user:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Environment]
"Hello"="echo Hello world!"
For all users:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"Hello"="echo Hello world!"
Using:
C:\>%hello%
Hello world!
For removing by command line:
For current user:
reg delete HKCU\Environment /v Hello /f
For all users:
reg delete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Hello /f
For removing by File.reg
For current user:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Environment]
"Hello"=-
For current all users:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"Hello"=-
bat
/cmd
which calls hello.bat, but the hello.bat call never returns. The solution for that is to usecall hello.bat
, rather than eliminating hello.bat.