Diego (Gast) - 10. Okt, 12:33

Ampersand & RunAs command

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:
  1. You cannot use replace (%<var>:<search>=<replacement>%) on parameters, so you have to assign it to a local variable first.
  2. 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.

Name

Url

Meine Eingaben merken?

Titel:

Text:


JCaptcha - du musst dieses Bild lesen können, um das Formular abschicken zu können
Neues Bild

 

Reflog

Informationstechnische Howtos, Hinweise und Merkwürdiges

Batchlib v1.0 2008-03-29

Aktuelle Beiträge

HOWTO_ O2 DSL Surf &...
Der O2 DSL Surf & Phone-Router ist für die alleinige...
cypressor - 12. Feb, 19:57
Uptweak Windows XP Home...
There are a lot of annoying limitations in Windows...
cypressor - 9. Okt, 19:30
BATCHLIB_ Batchlib package...
Download Batchlib package v1.0 (5 KB zip file) What...
cypressor - 29. Mär, 19:10
BATCHLIB_ Batchlib library...
The batchlib library string.cmd is part of the batchlib...
cypressor - 29. Mär, 18:10

Homepage Ticker

Links

Status

Online seit 6815 Tagen
Zuletzt aktualisiert: 28. Jun, 11:32
RSS XML 1.0 Button-Get-Firefox

batch
batchlib
howto
tech
video
Profil
Abmelden
Weblog abonnieren