Assuming you have copied the code correctly - it does nothing special at all. The
:"="" literal is simply appended to the expanded argument string.
If you had
%*:"=""% (note the additional percent), then it would expand an environment variable named
*, substituting two quotes for every one.
The Find/Replace expansion feature is only available to variable expansion, not argument expansion.
I'd be willing to bet it is a bug introduced by someone who has very little experience with the batch language.
There is almost surely another bug - All spaces in the assignment are significant. So it is creating a variable named
"params " (without the quotes, note the trailing space). Also, the value will have a leading space. I'm pretty sure neither space is wanted.
Updated, more complete answer
Now that we know the source of the code, it is possible to give a more complete picture as to what is going on. More code context is needed.
The original relevant lines are:
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
The original batch script required that it be run with elevated admin privileges. The script was able to determine if admin privs were available, and if not, then it created a temporary VBS script that when run, would create a new cmd.exe session with admin privs, and rerun the original batch script with the same original arguments. The command to rerun the script is embedded in a VBS string, and the string may include quoted arguments. VBS requires that quote literals within a string be escaped by doubling them.
The original answer did not preserve the arguments, and did not have any
params variable. One year later, the OP attempted to extend the answer to support preservation of the calling arguments. Unfortunately, the modified code was never properly tested, and the "enhancement" was seriously bugged. If you look at the many comments to that answer, you can see many reports that the argument preservation was still not working.
First off, the code defines a variable named "params " (with trailing space), and then attempts to use an undefined variable named "params" (without trailing space). That obviously can't work. But simply removing the spaces from the definition does not solve anything.
The OP must have thought that syntax would expand to the original argument string, with all quotes doubled. But find/replace only works when expanding variables, not arguments.
Assume the original batch script is
c:\test\test.bat, and it is called using
test arg1 "arg 2" "arg 3"
The "corrected" line
set params=%*:"="" simply gets a copy of the arguments with
%*, and then appends the
:"="" string. So when complete, the variable is defined as follows:
params=arg1 "arg 2" "arg 3":"=""
But the OP actually wanted:
params=arg1 ""arg 2"" ""arg 3""
The next line that is used to re-execute the script with admin privileges would fail. It would expand to:
echo UAC.ShellExecute "cmd.exe", "/c ""c:\test\test.bat"" arg1 "arg 2" "arg 3":"=""", "", "runas", 1 >> "someTempPath\getadmin.vbs"
Here is the code as it should have been written:
EDIT 2018-9-23: added space to params assignment to make sure it is always defined, even if no arguments
set params= %*
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
The first line simply defines params as
params= arg1 "arg 2" "arg 3"
And the next line uses the
:"="" syntax to double all quotes while expanding the
echo UAC.ShellExecute "cmd.exe", "/c ""c:\test\test.bat"" arg1 ""arg 2"" ""arg 3""", "", "runas", 1 >> "someTempPath\getadmin.vbs"
The original arguments are preserved, and all quotes have been properly doubled.
I have edited the original answer to incorporate the bug fixes.