0 Replies Latest reply on Jul 1, 2020 1:11 PM by MiMenl

    Command line test program

    MiMenl Novice



      I dont know if this is the right place for this but I think it might come in handy in the context of appvolumes.

      if it needs to be put somewere else feel free to move it to another section of the forum.


      While trying to automate installations to create appstacks, which I do in powershell I often run into the issue that my arguments are not parsed the right way,

      this usually happens when I need to combine a lot of argumenst with the -ArgumentList option in powershell.


      Since it sometimes is hard to track what actually happens I wrote a small program which can be used to replace the executable you want to install.

      The program wil show you the way the arguments are fed to the executable.


      Its a very small and actually very easy program to make but it really helps me so it might also help others.


      I'll add the source to this post, and will explain the code a bit too within the code with some remarks.


      Public Class Form1
          Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
              Dim commandlimeargs As String() = Nothing
              'get commandline parameters
              commandlimeargs = Environment.GetCommandLineArgs()
              For i = 0 To commandlimeargs.Length - 1
                  'create nice numbering of parameters to keep stuff alinged
                  If i < 10 Then
                      TextBox1.Text = TextBox1.Text & "Parameter 0" & i & " = " & commandlimeargs(i).ToString & vbCrLf
                      TextBox1.Text = TextBox1.Text & "Parameter " & i & " = " & commandlimeargs(i).ToString & vbCrLf
                  End If
              'set cursor at the end of the texttbox
              TextBox1.SelectionStart = TextBox1.Text.Length
          End Sub
          Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          End Sub
          Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
              'show teh about form
          End Sub
          Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
              'some resizing logic
              TextBox1.Width = Me.Width - 40
              Button1.Left = Me.Width - Button1.Width - 28
              TextBox1.Height = Me.Height - 100
              Button1.Top = Me.Height - 65
          End Sub
      End Class


      The program in action with some bogus parameters


      Execution string :


      Start-Process -PassThru -Wait -FilePath "c:\cmdtest.exe" -ArgumentList"/admin","/a","/I","/L*","`"D:\!TestMap\Log\CMDtest.log`"","/n","/q","/s","/v","/Passive","/norestart","REBOOT=ReallySuppress","/qn","/test bla /reboot=True","/adminfile","`"D:\!TestMap\Software Root\Transform_File.MSP`"","/config","`"D:\!TestMap\Software Root\Config_File.XML`""


      In powershell :




      Result :



      In this case you can see the first argument is not right since -argumentlist/admin should have been split

      this happend because I forgot a space between -ArgumentList"/admin"


      The right string would be :


      Start-Process -PassThru -Wait -FilePath "c:\cmdtest.exe" -ArgumentList "/admin","/a","/I","/L*","`"D:\!TestMap\Log\CMDtest.log`"","/n","/q","/s","/v","/Passive","/norestart","REBOOT=ReallySuppress","/qn","/test bla /reboot=True","/adminfile","`"D:\!TestMap\Software Root\Transform_File.MSP`"","/config","`"D:\!TestMap\Software Root\Config_File.XML`""


      This will give this result :




      Every parameter on a separate line which is the right way.

      It really saved me quite some time debugging my scripts hope it helps others too.


      I also started a project to save and generate powershellscripts trough gui for easy installs, but never got to finishing it, I might start working on that one again too if there is any interest, maybe even start a blog about it so let me know if you think it might be usefull.