自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ASP.NET關(guān)機(jī)代碼(Windows為本機(jī))

開發(fā) 后端
本文列出了ASP.NET的關(guān)機(jī)代碼的關(guān)機(jī)代碼,希望對大家有所幫助。

編寫.NET關(guān)機(jī)代碼,首先導(dǎo)入這個命名空間using System.Runtime.InteropServices;

這個是關(guān)閉本機(jī)的代碼,比如說程序是放在服務(wù)器上,那么關(guān)閉的是Server,而不是客戶端。

以下.NET關(guān)機(jī)代碼針對windows

  1. using System;    
  2. using System.Data;    
  3. using System.Configuration;    
  4. using System.Web;    
  5. using System.Web.Security;    
  6. using System.Web.UI;    
  7. using System.Web.UI.WebControls;    
  8. using System.Web.UI.WebControls.WebParts;    
  9. using System.Web.UI.HtmlControls;    
  10. using System.Runtime.InteropServices;    
  11.  
  12. public partial class _Default : System.Web.UI.Page     
  13.  
  14. {    
  15.     protected void Page_Load(object sender, EventArgs e)    
  16.     {    
  17.         DoExitWin(EWX_SHUTDOWN);    
  18.     }    
  19.     [StructLayout(LayoutKind.Sequential, Pack = 1)]    
  20.     internal struct TokPriv1Luid    
  21.     {    
  22.         public int Count;    
  23.         public long Luid;    
  24.         public int Attr;    
  25.     }    
  26.    
  27. [DllImport("kernel32.dll", ExactSpelling = true)]    
  28.    internal static extern IntPtr GetCurrentProcess();    
  29.    
  30.    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]    
  31.    internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);    
  32.    
  33.    [DllImport("advapi32.dll", SetLastError = true)]    
  34.    internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);    
  35.    
  36.    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]    
  37.    internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,    
  38.    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);    
  39.    
  40.    [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]    
  41.    internal static extern bool ExitWindowsEx(int flg, int rea);    
  42.  
  43. internal const int SE_PRIVILEGE_ENABLED = 0x00000002;    
  44.    internal const int TOKEN_QUERY = 0x00000008;    
  45.    internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;    
  46.    internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";    
  47.    internal const int EWX_LOGOFF = 0x00000000;    
  48.    internal const int EWX_SHUTDOWN = 0x00000001;    
  49.    internal const int EWX_REBOOT = 0x00000002;    
  50.    internal const int EWX_FORCE = 0x00000004;    
  51.    internal const int EWX_POWEROFF = 0x00000008;    
  52.    internal const int EWX_FORCEIFHUNG = 0x00000010;    
  53.  
  54. private static void DoExitWin(int flg)    
  55.     {    
  56.         bool ok;    
  57.         TokPriv1Luid tp;    
  58.         IntPtr hproc = GetCurrentProcess();    
  59.         IntPtr htok = IntPtr.Zero;    
  60.         ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);    
  61.         tp.Count = 1;    
  62.         tp.Luid = 0;    
  63.         tp.Attr = SE_PRIVILEGE_ENABLED;    
  64.         ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);    
  65.         ok = AdjustTokenPrivileges(htok, falseref tp, 0, IntPtr.Zero, IntPtr.Zero);    
  66.         ok = ExitWindowsEx(flg, 0);    
  67.     }    
  68. }    
  69.  

以上就是.NET關(guān)機(jī)代碼。

【編輯推薦】

  1. ASP.NET DetailsView中顯示選中產(chǎn)品的詳細(xì)信息
  2. ASP.NET 2.0數(shù)據(jù)教程:GridView選擇行
  3. ASP.NET 2.0數(shù)據(jù)教程:GridView顯示數(shù)據(jù)
  4. ASP.NET 2.0中添加GridView到頁面
  5. 新增ASP.NET頁面時的注意事項
責(zé)任編輯:book05 來源: cnblogs
相關(guān)推薦

2009-08-04 17:16:16

ASP.NET代碼優(yōu)化

2009-07-22 17:45:35

ASP.NET教程

2009-08-03 14:22:33

什么是ASP.NET

2009-07-28 17:17:19

ASP.NET概述

2012-05-07 14:50:32

ASP.NET

2009-08-10 17:17:10

ASP.NET安裝部署

2009-08-04 11:29:14

HTML代碼ASP.NET控件

2009-02-10 10:07:48

ASP.NETContextMenuVisual Stud

2009-07-29 15:51:29

ASP.NET中執(zhí)行w

2009-07-27 12:22:03

ASP.NET和ASPASP.NET入門教程

2009-07-28 16:31:03

Windows 200

2009-08-10 13:32:15

ASP.NET TimASP.NET組件設(shè)計

2009-07-29 17:11:25

ASP.NET ISA

2009-08-05 16:59:55

ASP.NET組件設(shè)計

2009-07-22 17:35:23

代碼隱藏文件ASP.NET

2009-07-30 14:26:30

ASP.NET常用代碼

2009-04-02 11:00:09

微軟ASP.NETMVC

2009-07-30 14:32:18

ASP.NET常用代碼

2009-07-29 16:08:07

ASP和ASP.NET

2009-08-03 13:38:18

ASP.NET編程模型
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號