Pass string with quotes from batch file to VBScript?












-1















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?










share|improve this question




















  • 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 the WScript.Shell object.

    – MC ND
    Jan 18 at 18:31


















-1















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?










share|improve this question




















  • 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 the WScript.Shell object.

    – MC ND
    Jan 18 at 18:31
















-1












-1








-1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 the WScript.Shell object.

    – MC ND
    Jan 18 at 18:31
















  • 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 the WScript.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














1 Answer
1






active

oldest

votes


















-1














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.






share|improve this answer



















  • 1





    That's the normal way of handling this.

    – catcat
    Jan 18 at 19:20











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
});


}
});














draft saved

draft discarded


















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









-1














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.






share|improve this answer



















  • 1





    That's the normal way of handling this.

    – catcat
    Jan 18 at 19:20
















-1














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.






share|improve this answer



















  • 1





    That's the normal way of handling this.

    – catcat
    Jan 18 at 19:20














-1












-1








-1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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














  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage