473,561 Members | 3,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to implement shutdown hook ?

Hi,

I am developing an infrastructure dll in c#.
my dll can be use by all kind of application containers win/web/console.
how do i implement a shutdown hook which will be called when the user exit
from the application (for all kind of .NET applications)?

for example in c# console application i do this with win32 interop
SetConsoleCtrlH andler function, but how do i know what kind of application
loaded my dll.

Thanks.

Nov 27 '05 #1
4 9592
Hi,

You have to detect the windows messages your app receive when the system is
going down, I do not remember the names ( you could search for it either in
google of in the .h files ) I do interact with the logoff event, for this I
use WM_ENDSESSION/ WM_QUERYENDSESS ION

Take a look at the MSDN about them
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussi ons.microsoft.c om> wrote in message
news:4D******** *************** ***********@mic rosoft.com...
Hi,

I am developing an infrastructure dll in c#.
my dll can be use by all kind of application containers win/web/console.
how do i implement a shutdown hook which will be called when the user exit
from the application (for all kind of .NET applications)?

for example in c# console application i do this with win32 interop
SetConsoleCtrlH andler function, but how do i know what kind of application
loaded my dll.

Thanks.

Nov 28 '05 #2
Hi Ignacio Machin,

is it good also for c# console applications ?

Thanks.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

You have to detect the windows messages your app receive when the system is
going down, I do not remember the names ( you could search for it either in
google of in the .h files ) I do interact with the logoff event, for this I
use WM_ENDSESSION/ WM_QUERYENDSESS ION

Take a look at the MSDN about them
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussi ons.microsoft.c om> wrote in message
news:4D******** *************** ***********@mic rosoft.com...
Hi,

I am developing an infrastructure dll in c#.
my dll can be use by all kind of application containers win/web/console.
how do i implement a shutdown hook which will be called when the user exit
from the application (for all kind of .NET applications)?

for example in c# console application i do this with win32 interop
SetConsoleCtrlH andler function, but how do i know what kind of application
loaded my dll.

Thanks.


Nov 29 '05 #3
Hi,

I do not think so, a Console app does not have a message pump, so you get
no messages from the OS, no idea how to do it in that case

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussi ons.microsoft.c om> wrote in message
news:84******** *************** ***********@mic rosoft.com...
Hi Ignacio Machin,

is it good also for c# console applications ?

Thanks.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

You have to detect the windows messages your app receive when the system
is
going down, I do not remember the names ( you could search for it either
in
google of in the .h files ) I do interact with the logoff event, for this
I
use WM_ENDSESSION/ WM_QUERYENDSESS ION

Take a look at the MSDN about them
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussi ons.microsoft.c om> wrote in message
news:4D******** *************** ***********@mic rosoft.com...
> Hi,
>
> I am developing an infrastructure dll in c#.
> my dll can be use by all kind of application containers
> win/web/console.
> how do i implement a shutdown hook which will be called when the user
> exit
> from the application (for all kind of .NET applications)?
>
> for example in c# console application i do this with win32 interop
> SetConsoleCtrlH andler function, but how do i know what kind of
> application
> loaded my dll.
>
> Thanks.
>


Nov 29 '05 #4
Thanks Ignacio Machin,

for console you can do it with SetConsoleCtrlH andler , see GC.KeepAlive
method sample in the MSDN help.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

I do not think so, a Console app does not have a message pump, so you get
no messages from the OS, no idea how to do it in that case

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussi ons.microsoft.c om> wrote in message
news:84******** *************** ***********@mic rosoft.com...
Hi Ignacio Machin,

is it good also for c# console applications ?

Thanks.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

You have to detect the windows messages your app receive when the system
is
going down, I do not remember the names ( you could search for it either
in
google of in the .h files ) I do interact with the logoff event, for this
I
use WM_ENDSESSION/ WM_QUERYENDSESS ION

Take a look at the MSDN about them
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussi ons.microsoft.c om> wrote in message
news:4D******** *************** ***********@mic rosoft.com...
> Hi,
>
> I am developing an infrastructure dll in c#.
> my dll can be use by all kind of application containers
> win/web/console.
> how do i implement a shutdown hook which will be called when the user
> exit
> from the application (for all kind of .NET applications)?
>
> for example in c# console application i do this with win32 interop
> SetConsoleCtrlH andler function, but how do i know what kind of
> application
> loaded my dll.
>
> Thanks.
>


Nov 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2755
by: Jonathan Heath | last post by:
Hi all, I have created an ASP script that enters data into an Access Database. My problem is that I'd like this script to run when the computer is shutdown or the user logs off. I think this would be simple enough if the ASP didn't have any user input, but it does.
0
1892
by: Allan Bredahl | last post by:
Hi All I am trying to construct an application that is able to cancel a machine shutdown, reboot or logoff. And after performing some stuff to perform the original shutdown order : Shutdown/reboot/logoff. I have tried this : AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf
3
1189
by: Senthil | last post by:
Hi, I would like to know the code for reboot and shutdown windows xp professional using VB.Net. thanx Senthil
4
18097
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call...
2
11391
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use...
10
10565
by: Steve | last post by:
Does any one know if python has the ability to run a shutdown hook. For example you set a method to run when the python process is shutting down, like it recieved a kill signal? Basically looking for an effect like the following java code. Runtime.getRuntime().addShutdownHook(new Thread(this));
0
2483
by: zeng.hui.stephen | last post by:
I download the demo http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I inherite the demo, and write my code. I want to use Hook to monitor C++ Edit change. I use a C# form containing a Edit(textbox) and button to test at first. When I change text in Edit or press button to setText value, I want to monitor the change event. ...
5
17395
by: Phil Tusa | last post by:
Greetings to all .... I have a need to issue a shutdown and/or Restart Windows XP inside my application. Any help or example code would be appreciated! -- Phil
22
6403
by: schneider | last post by:
I need to hook the system mouse down event. I'm trying to replicate how a context menu hides when the mouse clicks outside of the control. Thanks, Schneider
0
7639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8074
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7608
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5181
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3613
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
885
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.