Quantcast
Viewing all articles
Browse latest Browse all 27072

How to run Console Application in background or minimized?

I have a console application written in VB.NET that will become a scheduled task. The problem is that every time application starts it displays the empty black CMD window while processing, which can be distracting. How can I configure it to run in the background (with no CMD window displayed) or minimized?

Code:

Imports System.Net.Mail
Imports System.IO

Module Module1

    Sub Main()
        Dim message As New MailMessage
        Dim smtp As New SmtpClient
        Dim sr As StreamReader
        Dim email As String
        Dim filename As String = "email.txt"

        If My.Computer.FileSystem.FileExists(filename) Then
            sr = New StreamReader(filename)
            email = sr.ReadLine

            sr.Close()
        Else
            Console.WriteLine("Please enter an email address")
            email = Console.ReadLine()
            If email <> "" Then
                My.Computer.FileSystem.WriteAllText(filename, email, True)
            End If
        End If

        If email <> "" And InStr(email, "@") Then
            Console.WriteLine("Email Address Chosen Is: '" & email & "'")
            Console.WriteLine("Attempting to send email...")
            Try
                message.To.Add(email)
                message.From = New MailAddress("my.email@address.com", "E-mail Heading")
                message.Subject = ("Subject")
                message.Body = ("Content")

                smtp.Host = "smtp.gmail.com"
                smtp.Port = "587"

                smtp.EnableSsl = True
                smtp.Credentials = New Net.NetworkCredential("ccc.ddd@gmail.com", "password")
                smtp.Send(message)
                Console.WriteLine("Email has been sent!")

            Catch ex As Exception
                Console.WriteLine("Email has not been sent!")
                Console.WriteLine(ex.Message)


            End Try
        ElseIf Not InStr(email, "@") Then
            Console.WriteLine("Email address does not appear to be valid.")
            My.Computer.FileSystem.DeleteFile(filename)

        Else
            Console.WriteLine("Email address cannot be blank.")
        End If
        Console.WriteLine("Press Enter to Exit")
        Console.ReadLine()
    End Sub

End Module


Viewing all articles
Browse latest Browse all 27072


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>