I have a batch script:
test.bat
echo first arg is %1
pause
That I want to invoke from a vbscript with admin rights like so:
test.vbs
Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "test.bat", "argument", "", "runas", 1
This works ok but I am unable to pass a path argument that contains spaces as a single argument. Basically, I need to enclose the argument in spaces but whatever I try, it doesn't work. It looks like it invokes the batch, but the cmd window just flashes up and disappears so I don't know what is going wrong.
I've tried:
UAC.ShellExecute "test.bat", """has spaces""", "", "runas", 1
and
UAC.ShellExecute "test.bat", Chr(34) & "has spaces" & Chr(34), "", "runas", 1
and
UAC.ShellExecute "test.bat", '"has spaces"', , "runas", 1
and
UAC.ShellExecute "cmd", "/c test.bat " & chr(34) & "has spaces" & chr(34), "", "runas", 1
But no luck. Any suggestions what I'm doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…