Hi!
Your post was one the best I found in Google.
But I'm still cannot figure out how to do this:
runas /u:%user% "cmd /c %1"
%1 contains "&" symbol
Example: "X:\path\A & B.lnk"
I'll really appreciate your help.
Diego
xdmvDELETE-THIS[at]yahoo.com
cypressor - 22. Okt, 22:10
Re: Ampersand & RunAs command
Hi Diego,
the Batch replaces your variable %1 and after that it parses the command. As the ampersand has a higher weight than the quotes it breaks down your input into the two commands runas /u:username "cmd /c X:\path\A and B.lnk"
To avoid this, you have to escape the ampersand in your parameter:
set temp="%~1"
runas /u:%user% "cmd /c %temp:&=^&%"
Please note:
You cannot use replace (%<var>:<search>=<replacement>%) on parameters, so you have to assign it to a local variable first.
To assign the variable correctly, the value has to be quoted. To avoid double quoting (if the parameter is already quoted), the quotes are being removed using the tilde (~).
Ampersand & RunAs command
Your post was one the best I found in Google.
But I'm still cannot figure out how to do this:
runas /u:%user% "cmd /c %1"
%1 contains "&" symbol
Example: "X:\path\A & B.lnk"
I'll really appreciate your help.
Diego
xdmvDELETE-THIS[at]yahoo.com
Re: Ampersand & RunAs command
the Batch replaces your variable %1 and after that it parses the command. As the ampersand has a higher weight than the quotes it breaks down your input into the two commands runas /u:username "cmd /c X:\path\A and B.lnk"
To avoid this, you have to escape the ampersand in your parameter:
runas /u:%user% "cmd /c %temp:&=^&%"
Please note:
- You cannot use replace (%<var>:<search>=<replacement>%) on parameters, so you have to assign it to a local variable first.
- To assign the variable correctly, the value has to be quoted. To avoid double quoting (if the parameter is already quoted), the quotes are being removed using the tilde (~).
Hope that I could be of any help.