Pass string with quotes from batch file to VBScript?
I'm trying to pass a string parameter from a batch file to a vbs script that includes strings and I'm having some issues. I've tried a few variants but can't get it right.
_execute.vbs
:
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream(1)
Set stderr = fso.GetStandardStream(2)
stdout.Write WScript.Arguments.Item(0) & "... "
Dim objShell, oExec
Set objShell = WScript.CreateObject ("WScript.Shell")
intReturn = objShell.Run(WScript.Arguments.Item(1), 0, True)
if intReturn = 0 Then
stdout.WriteLine "Done"
Else
stderr.WriteLine "Error (Return Code: " & intReturn & ") trying to execute [" & WScript.Arguments.Item(1) & "]"
End If
First try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ""Default Web Site"" -name:Stream"
Output:
Installing IIS... Error (Return Code: 87) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site Default Web Site -name:Stream]
Second try:
install.bat
:
@echo off
cscript /nologo _execute.vbs 'Installing IIS' 'C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream'
Output:
'Installing... C:DEV_execute.vbs(8, 1) (null): The system cannot find the file specified.
Third try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ^"Default Web Site^" -name:Stream"
Output:
Installing IIS... Error (Return Code: 1168) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site ^Default]
How can I pass two parameters that are strings that may include quotes?
batch-file vbscript
add a comment |
I'm trying to pass a string parameter from a batch file to a vbs script that includes strings and I'm having some issues. I've tried a few variants but can't get it right.
_execute.vbs
:
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream(1)
Set stderr = fso.GetStandardStream(2)
stdout.Write WScript.Arguments.Item(0) & "... "
Dim objShell, oExec
Set objShell = WScript.CreateObject ("WScript.Shell")
intReturn = objShell.Run(WScript.Arguments.Item(1), 0, True)
if intReturn = 0 Then
stdout.WriteLine "Done"
Else
stderr.WriteLine "Error (Return Code: " & intReturn & ") trying to execute [" & WScript.Arguments.Item(1) & "]"
End If
First try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ""Default Web Site"" -name:Stream"
Output:
Installing IIS... Error (Return Code: 87) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site Default Web Site -name:Stream]
Second try:
install.bat
:
@echo off
cscript /nologo _execute.vbs 'Installing IIS' 'C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream'
Output:
'Installing... C:DEV_execute.vbs(8, 1) (null): The system cannot find the file specified.
Third try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ^"Default Web Site^" -name:Stream"
Output:
Installing IIS... Error (Return Code: 1168) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site ^Default]
How can I pass two parameters that are strings that may include quotes?
batch-file vbscript
2
Have you try to use backslash?cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream"
– Brank Victoria
Jan 18 at 16:31
The argument parser will consume the quotes in the command line so you can't (no without your own argument handling code, more here). A simple solution could be to store the command in a variable in the batch file and retrieve it inside the script using the.Environment
collection of theWScript.Shell
object.
– MC ND
Jan 18 at 18:31
add a comment |
I'm trying to pass a string parameter from a batch file to a vbs script that includes strings and I'm having some issues. I've tried a few variants but can't get it right.
_execute.vbs
:
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream(1)
Set stderr = fso.GetStandardStream(2)
stdout.Write WScript.Arguments.Item(0) & "... "
Dim objShell, oExec
Set objShell = WScript.CreateObject ("WScript.Shell")
intReturn = objShell.Run(WScript.Arguments.Item(1), 0, True)
if intReturn = 0 Then
stdout.WriteLine "Done"
Else
stderr.WriteLine "Error (Return Code: " & intReturn & ") trying to execute [" & WScript.Arguments.Item(1) & "]"
End If
First try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ""Default Web Site"" -name:Stream"
Output:
Installing IIS... Error (Return Code: 87) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site Default Web Site -name:Stream]
Second try:
install.bat
:
@echo off
cscript /nologo _execute.vbs 'Installing IIS' 'C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream'
Output:
'Installing... C:DEV_execute.vbs(8, 1) (null): The system cannot find the file specified.
Third try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ^"Default Web Site^" -name:Stream"
Output:
Installing IIS... Error (Return Code: 1168) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site ^Default]
How can I pass two parameters that are strings that may include quotes?
batch-file vbscript
I'm trying to pass a string parameter from a batch file to a vbs script that includes strings and I'm having some issues. I've tried a few variants but can't get it right.
_execute.vbs
:
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream(1)
Set stderr = fso.GetStandardStream(2)
stdout.Write WScript.Arguments.Item(0) & "... "
Dim objShell, oExec
Set objShell = WScript.CreateObject ("WScript.Shell")
intReturn = objShell.Run(WScript.Arguments.Item(1), 0, True)
if intReturn = 0 Then
stdout.WriteLine "Done"
Else
stderr.WriteLine "Error (Return Code: " & intReturn & ") trying to execute [" & WScript.Arguments.Item(1) & "]"
End If
First try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ""Default Web Site"" -name:Stream"
Output:
Installing IIS... Error (Return Code: 87) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site Default Web Site -name:Stream]
Second try:
install.bat
:
@echo off
cscript /nologo _execute.vbs 'Installing IIS' 'C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream'
Output:
'Installing... C:DEV_execute.vbs(8, 1) (null): The system cannot find the file specified.
Third try:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site ^"Default Web Site^" -name:Stream"
Output:
Installing IIS... Error (Return Code: 1168) trying to execute [C:WindowsSysWOW64inetsrvappcmd set site ^Default]
How can I pass two parameters that are strings that may include quotes?
batch-file vbscript
batch-file vbscript
edited Jan 18 at 19:14
Ansgar Wiechers
142k13126185
142k13126185
asked Jan 18 at 16:15
Scott BeesonScott Beeson
7,6782078149
7,6782078149
2
Have you try to use backslash?cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream"
– Brank Victoria
Jan 18 at 16:31
The argument parser will consume the quotes in the command line so you can't (no without your own argument handling code, more here). A simple solution could be to store the command in a variable in the batch file and retrieve it inside the script using the.Environment
collection of theWScript.Shell
object.
– MC ND
Jan 18 at 18:31
add a comment |
2
Have you try to use backslash?cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream"
– Brank Victoria
Jan 18 at 16:31
The argument parser will consume the quotes in the command line so you can't (no without your own argument handling code, more here). A simple solution could be to store the command in a variable in the batch file and retrieve it inside the script using the.Environment
collection of theWScript.Shell
object.
– MC ND
Jan 18 at 18:31
2
2
Have you try to use backslash?
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream"
– Brank Victoria
Jan 18 at 16:31
Have you try to use backslash?
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream"
– Brank Victoria
Jan 18 at 16:31
The argument parser will consume the quotes in the command line so you can't (no without your own argument handling code, more here). A simple solution could be to store the command in a variable in the batch file and retrieve it inside the script using the
.Environment
collection of the WScript.Shell
object.– MC ND
Jan 18 at 18:31
The argument parser will consume the quotes in the command line so you can't (no without your own argument handling code, more here). A simple solution could be to store the command in a variable in the batch file and retrieve it inside the script using the
.Environment
collection of the WScript.Shell
object.– MC ND
Jan 18 at 18:31
add a comment |
1 Answer
1
active
oldest
votes
I ended up just using a single quote in the batch file
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site 'Default Web Site' -name:Stream"
and replacing them with double quotes in the VBS file.
Replace(WScript.Arguments.Item(1),"'",chr(34))
It's not ideal, but it works for my uses.
1
That's the normal way of handling this.
– catcat
Jan 18 at 19:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257719%2fpass-string-with-quotes-from-batch-file-to-vbscript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I ended up just using a single quote in the batch file
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site 'Default Web Site' -name:Stream"
and replacing them with double quotes in the VBS file.
Replace(WScript.Arguments.Item(1),"'",chr(34))
It's not ideal, but it works for my uses.
1
That's the normal way of handling this.
– catcat
Jan 18 at 19:20
add a comment |
I ended up just using a single quote in the batch file
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site 'Default Web Site' -name:Stream"
and replacing them with double quotes in the VBS file.
Replace(WScript.Arguments.Item(1),"'",chr(34))
It's not ideal, but it works for my uses.
1
That's the normal way of handling this.
– catcat
Jan 18 at 19:20
add a comment |
I ended up just using a single quote in the batch file
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site 'Default Web Site' -name:Stream"
and replacing them with double quotes in the VBS file.
Replace(WScript.Arguments.Item(1),"'",chr(34))
It's not ideal, but it works for my uses.
I ended up just using a single quote in the batch file
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site 'Default Web Site' -name:Stream"
and replacing them with double quotes in the VBS file.
Replace(WScript.Arguments.Item(1),"'",chr(34))
It's not ideal, but it works for my uses.
answered Jan 18 at 18:42
Scott BeesonScott Beeson
7,6782078149
7,6782078149
1
That's the normal way of handling this.
– catcat
Jan 18 at 19:20
add a comment |
1
That's the normal way of handling this.
– catcat
Jan 18 at 19:20
1
1
That's the normal way of handling this.
– catcat
Jan 18 at 19:20
That's the normal way of handling this.
– catcat
Jan 18 at 19:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257719%2fpass-string-with-quotes-from-batch-file-to-vbscript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Have you try to use backslash?
cscript /nologo _execute.vbs "Installing IIS" "C:WindowsSysWOW64inetsrvappcmd set site "Default Web Site" -name:Stream"
– Brank Victoria
Jan 18 at 16:31
The argument parser will consume the quotes in the command line so you can't (no without your own argument handling code, more here). A simple solution could be to store the command in a variable in the batch file and retrieve it inside the script using the
.Environment
collection of theWScript.Shell
object.– MC ND
Jan 18 at 18:31