1

Im trying to call a simple VB sub from windows task scheduler, the vb script is found inside a very large project so I have created a new item inside the project just to test the execution of the script. For now im just trying to return a simple string so that the process will go like this and this is also how I am going to be debugging and testing this:

Windows Task Scheduler > cmd line > .vb > sub/method

This is the test class I am working with for now.

    Public Class clsSchedule


        Public Sub RunTasksFromCommandLine(ByVal lstrArgs() As String)
             Try
                 For i As Integer = 1 To lstrArgs.Length - 1 Step 1

                      lstrProcessKey = lstrArgs(i).Trim("-"c).Trim("/"c).ToUpper
                 Next i
             End Try
        End Sub
    End Class
  • Batch can only run programs and other batch scripts. Call the program that can run your VB code. – Henrik4 Apr 22 '20 at 17:24
  • You can modify your application to accept a specific commandline argument and then only run that one method when it detects it. It can then pass the other arguments to that method. – jmcilhinney Apr 22 '20 at 17:33

1 Answers1

0

If you want to execute VBScript code from command line you can use mshta like in this example:

mshta vbscript:Execute("Msgbox(""Are you sure?"",vbYesNo+vbInformation,"""")(window.close)")

you can also check this - Is it possible to embed and execute VBScript within a batch file without using a temporary file?

If you want to execute VB.NET from command line... then may be you try with powershell codeblocks. If you want to embed VB.NET code into batch file you can use msbuild inline tasks or to use the .net compiler to create self-compiling script.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • This would be a good alternative in case I cannot call the VB script at all. Thank you I will experiment with this. –  paddockson Apr 22 '20 at 17:59
  • I used this method and for using some simple logic this worked fine as a work around, thank you. –  paddockson Apr 23 '20 at 11:07
  • @paddockson - it is not possible to call code blocks directly from command line : https://stackoverflow.com/questions/61373052/how-i-can-use-add-type-in-powershell-through-command-line-in-order-to-execute-vb . So if you want VB.NET code you'll have to try self-compiled scripts like in the last link. – npocmaka Apr 23 '20 at 11:09