WScript.Shell Fails For Unknown Reasons VB6.5 [duplicate]












1
















This question already has an answer here:




  • VBS with Space in File Path

    4 answers




In VBA I am running a piece of external software I wrote. I know the software works well. I can run it from the command line. But when I attempt to execute it using WScript.Shell.Run, it returns a 1 and it never runs. I can't even tell that it executes the software at all.



Here is the executing portion of the VBA class.



Public Function Execute() As Integer
Dim wsh As Object
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim exitCode As Integer: exitCode = -1

Set wsh = VBA.CreateObject("WScript.Shell")

'Run program with arguments and wait for the program to finish
If Me.PrinterType = 1 Then exitCode = wsh.Run(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location & "", windowStyle, waitOnReturn)
If Me.PrinterType = 2 Then exitCode = wsh.Run(Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version, windowStyle, waitOnReturn)
Execute = exitCode

End Function


An example of the full execute string:




C:.path.to.PrintLabel.exe /serial=EOSJ61110044 /position=2




Evidence that the script runs without error from the same machine the VBA is executing on:
enter image description here



So I've got no idea what's going on.



I can use the following VBA Shell function successfully:



If Me.PrinterType = 1 Then exitCode = Shell(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location, vbHide)


But the problem then becomes that the VBA doesn't wait on the software to finish before continuing. So I need to continue to try and make WScript.Shell work. What am I missing? Are there any specific references that need to be enabled that I could be missing?



Update 1:



Tried this to mimic this SO post, but still didn't have success:



If Me.PrinterType = 1 Then fullExecutionString = Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location
If Me.PrinterType = 2 Then fullExecutionString = Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version
wsh.Run fullExecutionString, windowStyle, waitOnReturn


Update 2:
Made a small method that repeats the process in windows cmd console. It works (more or less) with the same code. I am guessing it has something to do with the command path string with arguments?



Private Sub Button2_Released()
Dim wsh As Object
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim exitCode As Integer: exitCode = 0
Set wsh = VBA.CreateObject("WScript.Shell")
exitCode = wsh.Run("C:WindowsSystem32cmd.exe", windowStyle, waitOnReturn)
End Sub









share|improve this question















marked as duplicate by GSerg vba
Users with the  vba badge can single-handedly close vba questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 8:49


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    1
















    This question already has an answer here:




    • VBS with Space in File Path

      4 answers




    In VBA I am running a piece of external software I wrote. I know the software works well. I can run it from the command line. But when I attempt to execute it using WScript.Shell.Run, it returns a 1 and it never runs. I can't even tell that it executes the software at all.



    Here is the executing portion of the VBA class.



    Public Function Execute() As Integer
    Dim wsh As Object
    Dim waitOnReturn As Boolean: waitOnReturn = True
    Dim windowStyle As Integer: windowStyle = 1
    Dim exitCode As Integer: exitCode = -1

    Set wsh = VBA.CreateObject("WScript.Shell")

    'Run program with arguments and wait for the program to finish
    If Me.PrinterType = 1 Then exitCode = wsh.Run(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location & "", windowStyle, waitOnReturn)
    If Me.PrinterType = 2 Then exitCode = wsh.Run(Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version, windowStyle, waitOnReturn)
    Execute = exitCode

    End Function


    An example of the full execute string:




    C:.path.to.PrintLabel.exe /serial=EOSJ61110044 /position=2




    Evidence that the script runs without error from the same machine the VBA is executing on:
    enter image description here



    So I've got no idea what's going on.



    I can use the following VBA Shell function successfully:



    If Me.PrinterType = 1 Then exitCode = Shell(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location, vbHide)


    But the problem then becomes that the VBA doesn't wait on the software to finish before continuing. So I need to continue to try and make WScript.Shell work. What am I missing? Are there any specific references that need to be enabled that I could be missing?



    Update 1:



    Tried this to mimic this SO post, but still didn't have success:



    If Me.PrinterType = 1 Then fullExecutionString = Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location
    If Me.PrinterType = 2 Then fullExecutionString = Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version
    wsh.Run fullExecutionString, windowStyle, waitOnReturn


    Update 2:
    Made a small method that repeats the process in windows cmd console. It works (more or less) with the same code. I am guessing it has something to do with the command path string with arguments?



    Private Sub Button2_Released()
    Dim wsh As Object
    Dim waitOnReturn As Boolean: waitOnReturn = True
    Dim windowStyle As Integer: windowStyle = 1
    Dim exitCode As Integer: exitCode = 0
    Set wsh = VBA.CreateObject("WScript.Shell")
    exitCode = wsh.Run("C:WindowsSystem32cmd.exe", windowStyle, waitOnReturn)
    End Sub









    share|improve this question















    marked as duplicate by GSerg vba
    Users with the  vba badge can single-handedly close vba questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 23 '18 at 8:49


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      1












      1








      1









      This question already has an answer here:




      • VBS with Space in File Path

        4 answers




      In VBA I am running a piece of external software I wrote. I know the software works well. I can run it from the command line. But when I attempt to execute it using WScript.Shell.Run, it returns a 1 and it never runs. I can't even tell that it executes the software at all.



      Here is the executing portion of the VBA class.



      Public Function Execute() As Integer
      Dim wsh As Object
      Dim waitOnReturn As Boolean: waitOnReturn = True
      Dim windowStyle As Integer: windowStyle = 1
      Dim exitCode As Integer: exitCode = -1

      Set wsh = VBA.CreateObject("WScript.Shell")

      'Run program with arguments and wait for the program to finish
      If Me.PrinterType = 1 Then exitCode = wsh.Run(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location & "", windowStyle, waitOnReturn)
      If Me.PrinterType = 2 Then exitCode = wsh.Run(Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version, windowStyle, waitOnReturn)
      Execute = exitCode

      End Function


      An example of the full execute string:




      C:.path.to.PrintLabel.exe /serial=EOSJ61110044 /position=2




      Evidence that the script runs without error from the same machine the VBA is executing on:
      enter image description here



      So I've got no idea what's going on.



      I can use the following VBA Shell function successfully:



      If Me.PrinterType = 1 Then exitCode = Shell(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location, vbHide)


      But the problem then becomes that the VBA doesn't wait on the software to finish before continuing. So I need to continue to try and make WScript.Shell work. What am I missing? Are there any specific references that need to be enabled that I could be missing?



      Update 1:



      Tried this to mimic this SO post, but still didn't have success:



      If Me.PrinterType = 1 Then fullExecutionString = Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location
      If Me.PrinterType = 2 Then fullExecutionString = Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version
      wsh.Run fullExecutionString, windowStyle, waitOnReturn


      Update 2:
      Made a small method that repeats the process in windows cmd console. It works (more or less) with the same code. I am guessing it has something to do with the command path string with arguments?



      Private Sub Button2_Released()
      Dim wsh As Object
      Dim waitOnReturn As Boolean: waitOnReturn = True
      Dim windowStyle As Integer: windowStyle = 1
      Dim exitCode As Integer: exitCode = 0
      Set wsh = VBA.CreateObject("WScript.Shell")
      exitCode = wsh.Run("C:WindowsSystem32cmd.exe", windowStyle, waitOnReturn)
      End Sub









      share|improve this question

















      This question already has an answer here:




      • VBS with Space in File Path

        4 answers




      In VBA I am running a piece of external software I wrote. I know the software works well. I can run it from the command line. But when I attempt to execute it using WScript.Shell.Run, it returns a 1 and it never runs. I can't even tell that it executes the software at all.



      Here is the executing portion of the VBA class.



      Public Function Execute() As Integer
      Dim wsh As Object
      Dim waitOnReturn As Boolean: waitOnReturn = True
      Dim windowStyle As Integer: windowStyle = 1
      Dim exitCode As Integer: exitCode = -1

      Set wsh = VBA.CreateObject("WScript.Shell")

      'Run program with arguments and wait for the program to finish
      If Me.PrinterType = 1 Then exitCode = wsh.Run(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location & "", windowStyle, waitOnReturn)
      If Me.PrinterType = 2 Then exitCode = wsh.Run(Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version, windowStyle, waitOnReturn)
      Execute = exitCode

      End Function


      An example of the full execute string:




      C:.path.to.PrintLabel.exe /serial=EOSJ61110044 /position=2




      Evidence that the script runs without error from the same machine the VBA is executing on:
      enter image description here



      So I've got no idea what's going on.



      I can use the following VBA Shell function successfully:



      If Me.PrinterType = 1 Then exitCode = Shell(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location, vbHide)


      But the problem then becomes that the VBA doesn't wait on the software to finish before continuing. So I need to continue to try and make WScript.Shell work. What am I missing? Are there any specific references that need to be enabled that I could be missing?



      Update 1:



      Tried this to mimic this SO post, but still didn't have success:



      If Me.PrinterType = 1 Then fullExecutionString = Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location
      If Me.PrinterType = 2 Then fullExecutionString = Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version
      wsh.Run fullExecutionString, windowStyle, waitOnReturn


      Update 2:
      Made a small method that repeats the process in windows cmd console. It works (more or less) with the same code. I am guessing it has something to do with the command path string with arguments?



      Private Sub Button2_Released()
      Dim wsh As Object
      Dim waitOnReturn As Boolean: waitOnReturn = True
      Dim windowStyle As Integer: windowStyle = 1
      Dim exitCode As Integer: exitCode = 0
      Set wsh = VBA.CreateObject("WScript.Shell")
      exitCode = wsh.Run("C:WindowsSystem32cmd.exe", windowStyle, waitOnReturn)
      End Sub




      This question already has an answer here:




      • VBS with Space in File Path

        4 answers








      vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 8:36







      Jaberwocky

















      asked Nov 23 '18 at 8:16









      JaberwockyJaberwocky

      7161318




      7161318




      marked as duplicate by GSerg vba
      Users with the  vba badge can single-handedly close vba questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 8:49


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by GSerg vba
      Users with the  vba badge can single-handedly close vba questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 8:49


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          Answering my own question:



          After much debugging I resolved that the path with spaces is causing the issue. If I directly input the following (notice the quote placement), the code successfully runs:



          exitCode = wsh.Run("""C:path.toPrintLabel.exe"" /serial=EOSJ61110044 /position=2", windowStyle, waitOnReturn)


          So in the end I adjusted my Path property:



          Public Property Let Path(ByVal NewValue As String)
          actPath = Chr(34) & NewValue & Chr(34)
          End Property
          Public Property Get Path() As String
          Path = actPath
          End Property





          share|improve this answer
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Answering my own question:



            After much debugging I resolved that the path with spaces is causing the issue. If I directly input the following (notice the quote placement), the code successfully runs:



            exitCode = wsh.Run("""C:path.toPrintLabel.exe"" /serial=EOSJ61110044 /position=2", windowStyle, waitOnReturn)


            So in the end I adjusted my Path property:



            Public Property Let Path(ByVal NewValue As String)
            actPath = Chr(34) & NewValue & Chr(34)
            End Property
            Public Property Get Path() As String
            Path = actPath
            End Property





            share|improve this answer






























              0














              Answering my own question:



              After much debugging I resolved that the path with spaces is causing the issue. If I directly input the following (notice the quote placement), the code successfully runs:



              exitCode = wsh.Run("""C:path.toPrintLabel.exe"" /serial=EOSJ61110044 /position=2", windowStyle, waitOnReturn)


              So in the end I adjusted my Path property:



              Public Property Let Path(ByVal NewValue As String)
              actPath = Chr(34) & NewValue & Chr(34)
              End Property
              Public Property Get Path() As String
              Path = actPath
              End Property





              share|improve this answer




























                0












                0








                0







                Answering my own question:



                After much debugging I resolved that the path with spaces is causing the issue. If I directly input the following (notice the quote placement), the code successfully runs:



                exitCode = wsh.Run("""C:path.toPrintLabel.exe"" /serial=EOSJ61110044 /position=2", windowStyle, waitOnReturn)


                So in the end I adjusted my Path property:



                Public Property Let Path(ByVal NewValue As String)
                actPath = Chr(34) & NewValue & Chr(34)
                End Property
                Public Property Get Path() As String
                Path = actPath
                End Property





                share|improve this answer















                Answering my own question:



                After much debugging I resolved that the path with spaces is causing the issue. If I directly input the following (notice the quote placement), the code successfully runs:



                exitCode = wsh.Run("""C:path.toPrintLabel.exe"" /serial=EOSJ61110044 /position=2", windowStyle, waitOnReturn)


                So in the end I adjusted my Path property:



                Public Property Let Path(ByVal NewValue As String)
                actPath = Chr(34) & NewValue & Chr(34)
                End Property
                Public Property Get Path() As String
                Path = actPath
                End Property






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 '18 at 8:56

























                answered Nov 23 '18 at 8:48









                JaberwockyJaberwocky

                7161318




                7161318

















                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()