Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
// Flags that end up in the event log code.
SHTDN_REASON_FLAG_USER_DEFINED = 0x40000000,
SHTDN_REASON_FLAG_PLANNED = 0x80000000,
SHTDN_REASON_UNKNOWN = SHTDN_REASON_MINOR_NONE,
SHTDN_REASON_LEGACY_API = (SHTDN_REASON_MAJOR_LEGACY_API | SHTDN_REASON_FLAG_PLANNED),
C# sample code: sivakumar.keerthi
***
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Runtime.InteropServices;
// This mask cuts out UI flags.
SHTDN_REASON_VALID_BIT_MASK = 0xc0ffffff
}
<DllImport("advapi32.dll", SetLastError:=True)> _
Public Function InitiateSystemShutdownEx( _
ByVal lpMachineName As String, _
ByVal lpMessage As String, _
ByVal Timeout As UInteger, _
<MarshalAs(UnmanagedType.Bool)> ByVal bForceAppsClosed As Boolean, _
<MarshalAs(UnmanagedType.Bool)> ByVal bRebootAfterShutdown As Boolean, _
ByVal ShutdownReason As ShutdownReason) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
public FrmMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Image Img = Image.FromFile( Application.StartupPath + "\\" + "ShutDown.gif" );
CmdShutDown.Image = Img;
this.ShowInTaskbar = false;
//
// TODO: Add any constructor code after InitializeComponent call
//
}
<Flags()> _
Public Enum ShutdownReason As UInteger
' Microsoft major reasons.
SHTDN_REASON_MAJOR_OTHER = &H0UI
SHTDN_REASON_MAJOR_NONE = &H0UI
SHTDN_REASON_MAJOR_HARDWARE = &H10000UI
SHTDN_REASON_MAJOR_OPERATINGSYSTEM = &H20000UI
SHTDN_REASON_MAJOR_SOFTWARE = &H30000UI
SHTDN_REASON_MAJOR_APPLICATION = &H40000UI
SHTDN_REASON_MAJOR_SYSTEM = &H50000UI
SHTDN_REASON_MAJOR_POWER = &H60000UI
SHTDN_REASON_MAJOR_LEGACY_API = &H70000UI
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
' Flags that end up in the event log code.
SHTDN_REASON_FLAG_USER_DEFINED = &H40000000UI
SHTDN_REASON_FLAG_PLANNED = &H80000000UI
SHTDN_REASON_UNKNOWN = SHTDN_REASON_MINOR_NONE
SHTDN_REASON_LEGACY_API = (SHTDN_REASON_MAJOR_LEGACY_API Or SHTDN_REASON_FLAG_PLANNED)
}
#endregion
' This mask cuts out UI flags.
SHTDN_REASON_VALID_BIT_MASK = &HC0FFFFFFUI
End Enum
User-Defined Types:
None.
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FrmMain());
}
Notes:
lpMachineName: The network name of the computer to be shut down. If lpMachineName is NULL or an empty string, the function shuts down the local computer.
dwReason: The ShutdownReason enum can be used for this parameter.
Public ErrMsg As String
Private Flag As Integer = 8
Function ShutdownPC(ByVal PC_Name As String, ByVal forced As Boolean) As Boolean
Dim wmi As ManagementClass
Dim objs As ManagementObjectCollection
Dim obj As ManagementObject
Dim Result As Integer
If forced = True Then
Flag += 4
End If
Try
wmi = New ManagementClass("\\" & PC_Name & "\root\cimv2:Win32_OperatingSystem")
objs = wmi.GetInstances()
For Each obj In objs
' Get an input parameters object for this method
Dim inParams As ManagementBaseObject = obj.GetMethodParameters("Win32Shutdown")
' fill 'em in
inParams("Flags") = Flag
inParams("Reserved") = 0
' do it!
Dim outParams As ManagementBaseObject = obj.InvokeMethod("Win32Shutdown", inParams, Nothing)
Result = Convert.ToInt32(outParams("returnValue"))
If Result <> 0 Then
ErrMsg = ErrorToString(Result)
Return False
End If
Exit For
Next
Catch ex As Exception
ErrMsg = ex.Message
Return False
End Try
Return True
End Function
TODO - a short description
12/14/2007 1:24:08 AM - anonymous
Defines the Shutdown reason for the user32.ExitWindowsEx method
5/7/2009 4:35:31 PM - -218.74.122.100
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).