Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

prevent system shutdown c#

public partial class Form1 : Form
{
    [DllImport("user32.dll")]
    public extern static bool ShutdownBlockReasonCreate(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pwszReason);

    private bool blocked = false;

    protected override void WndProc(ref Message aMessage)
    {
        const int WM_QUERYENDSESSION = 0x0011;
        const int WM_ENDSESSION = 0x0016;

        if (blocked && (aMessage.Msg == WM_QUERYENDSESSION || aMessage.Msg == WM_ENDSESSION))
            return;

        base.WndProc(ref aMessage);
    }

    void Button1_Click(object sender, FormClosingEventArgs e)
    {
        if (ShutdownBlockReasonCreate(this.Handle, "DONT:"))
        {
            blocked = true;
            MessageBox.Show("Shutdown blocking succeeded");
        }
        else
            MessageBox.Show("Shutdown blocking failed");
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: in c sharp how do you work the wait function 
Csharp :: c# loop array 
Csharp :: c# nullable generic 
Csharp :: regex for accepting a file name c# 
Csharp :: How to add rigidbody as a variable 
Csharp :: c# loop class properties add to array 
Csharp :: remove last instance of string c# 
Csharp :: how to turn on/off Particle System unity 
Csharp :: C# domain name to ip address 
Csharp :: c# move form without border 
Csharp :: unity check if current scene is being unloaded 
Csharp :: get ad user using email address microsoft graph C# 
Csharp :: c# get all letters 
Csharp :: C# max rand 
Csharp :: bytes size c# 
Csharp :: search for a substring in the registry 
Csharp :: how to change all values in dictionary c# 
Csharp :: onmousedown() not working unity 
Csharp :: entity framework with query C# 
Csharp :: how to add skybox in unity 
Csharp :: open linkedlabel c# 
Csharp :: stock span problem c# using class 
Csharp :: int array to frequency dictionary c# 
Csharp :: c# retry delay request 
Csharp :: speech 
Csharp :: c# internalsvisibleto 
Csharp :: How to jump in Unity using physics 3D 
Csharp :: curl rest api keycloak 
Csharp :: query associative table ef6 
Csharp :: JavaScriptSerializer() and convert to base64 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =