0
votes

I have a console app written in VB Net that works perfectly. Now I want to run it using task scheduler. The problem is that the app has a console.readline command at the very end that keeps the console window open until the user hits enter. Is there a way to test whether the app is running in a session or not?

If I knew that the app was not tied to a desktop console, I would not write the comments to the console and I'd bypass the final console.readline command.

1

1 Answers

4
votes

You should add an argument to your task to indicate it is unattended. For example, pass /u in your scheduled task. Check for /u in your program to determine if it should skip the console.readline.

enter image description here

excerpt from msdn forum

Dim args() As String = Environment.GetCommandLineArgs()

' args(0) = Full path of executing program with program name
' args(1) = First switch in command - /u
if args(1) = "/u" then ....

Or you can change the signature of your Main() to Public Sub Main(ByVal args() As String) and you won't need to use Dim args() As String = Environment.GetCommandLineArgs()