I use the compile type to decide to show the form (a debug info form only), or to just run the service like so:
Code:
<MTAThread()> Sub Main()
#If DEBUG Then
gfrmDebug = New frmDebug 'I hold a copy as I update it with stats
Application.Run(gfrmDebug)
#Else
'Run as a service, let it deal with everything, I might have more than 1, so use a loop, again you can remove the loop and just run 1 copy
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
ServicesToRun = New System.ServiceProcess.ServiceBase() {New clsServiceMain} 'This clsServiceMain is just a class that Inherits System.ServiceProcess.ServiceBase
For Each Service As System.ServiceProcess.ServiceBase In ServicesToRun
Service.CanPauseAndContinue = True
Service.CanShutdown = True
Service.AutoLog = True
Next
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
#End If
End Sub
Not exactly what you asked for, but you can use the bones. An alternative is to use command arguments, so when run as a service you can use MyExeName.exe /AsService
There is no method that I know of to tell you dynamically.