I have other service that run, for example real vnc, that don't shut down
"Skjoldmø" <IkkeMig@NN.com> wrote in message
news:OHKA%23yoJGHA.3176@TK2MSFTNGP12.phx.gbl...
> If the computer is member of a domain, or configured for CTRL+ALT+DELETE
> log on all progams but Windows will be closed at Log off.
>
> Skjoldmø
>
>
> "Rob Latour" <roblatour@rogers.com> wrote in message
> news:OJd$NFeJGHA.1088@tk2msftngp13.phx.gbl...
>>I am trying to run my app as a service using srvany.
>>
>> It loads and runs fine when windows starts. All is well when the user
>> logs on. However, when the user logs off the app unloads from memory and
>> is no longer running (but the service appears to be running).
>>
>> From what I've been able to determine to date, I need to handle the
>> CTRL_LOGOFF_EVENT so that my program doesn't unload when the user logs
>> off. I just can't seem to get it working:
>>
>> Here are some code snippets I am working with modeled after a good
>> article found at:
>>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemgcclasskeepalivetopic.asp
>>
>> Any help would be appreciated!
>>
>> With thanks, Rob
>>
>> Public Class MyWin32
>>
>> ' Declare the SetConsoleCtrlHandler function as external
>>
>> ' and receiving a delegate.
>>
>> <DllImport("Kernel32")> _
>>
>> Public Shared Function SetConsoleCtrlHandler(ByVal Handler As
>> HandlerRoutine, _
>>
>> ByVal Add As Boolean) As Boolean
>>
>> End Function
>>
>>
>>
>> ' A delegate type to be used as the handler routine
>>
>> ' for SetConsoleCtrlHandler.
>>
>> Delegate Function HandlerRoutine(ByVal CtrlType As CtrlTypes) As
>> [Boolean]
>>
>> ' An enumerated type for the control messages
>>
>> ' sent to the handler routine.
>>
>> Public Enum CtrlTypes
>>
>> CTRL_C_EVENT = 0
>>
>> CTRL_BREAK_EVENT = 1
>>
>> CTRL_CLOSE_EVENT = 2
>>
>> CTRL_LOGOFF_EVENT = 5
>>
>> CTRL_SHUTDOWN_EVENT = 6
>>
>> End Enum
>>
>> End Class
>>
>>
>>
>>
>>
>>
>> ****************************
>> the handler routine
>>
>> Shared Function ConsoleCtrlCheck(ByVal dwctrltype As MyWin32.CtrlTypes)
>> As Boolean
>>
>> Select Case dwctrltype
>>
>> Case MyWin32.CtrlTypes.CTRL_C_EVENT
>>
>> Debughandler("CTRL+C received!")
>>
>> Return True
>>
>> Case MyWin32.CtrlTypes.CTRL_BREAK_EVENT
>>
>> Debughandler("CTRL+BREAK received!")
>>
>> Return True
>>
>> Case MyWin32.CtrlTypes.CTRL_CLOSE_EVENT
>>
>> Debughandler("CLOSE received!")
>>
>> Return True
>>
>> Case MyWin32.CtrlTypes.CTRL_LOGOFF_EVENT
>>
>> Debughandler("LOGOFF received!")
>>
>> Beep()
>>
>> Beep()
>>
>> Beep()
>>
>> Return True
>>
>> Case MyWin32.CtrlTypes.CTRL_SHUTDOWN_EVENT
>>
>> Debughandler("SHUTDOWN received!")
>>
>> Return True
>>
>> End Select
>>
>> End Function
>>
>>
>>
>>
>>
>> ***********************
>>
>> in my main program (vb.net vs 2005) ....
>>
>>
>>
>> Dim hr As New MyWin32.HandlerRoutine(AddressOf ConsoleCtrlCheck)
>>
>> MyWin32.SetConsoleCtrlHandler(hr, True)
>>
>> System.Windows.Forms.Application.Run()
>>
>>
>
>