Environment Variables and string replacement for dos settings
(1) Use the wmic command to set the system environment variables. It takes effect directly under xp. win7 needs to restart the computer or go to computer-> properties-> advanced-> environment variables. Click "OK ".
@ Echo off
Set regpath = HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment
: Echo.
:: Echo ===================================================== ==========
: Echo installation settings
:: Echo ===================================================== ==========
: Echo.
: Set/p en = press enter to start installation! :
: Echo.
Set pwd = % cd %
: Reg add "% regpath %"/v "winrar"/d "% pwd % \ compact;"/f
: Echo.
: Echo new append environment variable path = % pwd % \ WinRAR
: For,/f, "skip = 4 token = 1, 2, *", % a, in, ('reg query "% regpath %"/v "path" '), do ,(
: Reg add "% regpath %"/v "path"/d "% c; % pwd % \ compact; % pwd % \ conf \ bin; % pwd % \ lib; "/f
::)
Wmic ENVIRONMENT where "name = 'path' and username = '<system>'" set VariableValue = "% path %; % pwd % \ compact; % pwd % \ conf \ bin; % pwd % \ lib ;"
Wmic ENVIRONMENT create name = "TESSDATA_PREFIX", username = "<system>", VariableValue = "% pwd % \ lib"
Echo.
(2) Replace the string. Note that you must replace the complex symbols in the string. You must use !!, The identifier must be added by setlocal enabledelayedexpansion and endlocal.
: Delete the environment variable of Path by replacing it with null.
Set p = % PATH %
Set pwd = % cd %
Set replace = % pwd % \ compact ^; % pwd % \ conf \ bin ^; % pwd % \ lib ^;
Setlocal enabledelayedexpansion
Set p =! P: % replace % =!
Wmic ENVIRONMENT where "name = 'path' and username = '<system>'" set VariableValue = "% p % ;"
Endlocal
(3) normally, replace string B in "aabbcc" with null.
Set a = "aabbcc"
Set B = % a: B = %
Echo % B %