网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C#应用
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用C#开发智能手机软件:推箱子(四.
.C#箴言:用静态构造函数初始化静.
.C#代表元及事件触发.
.防SQL注入攻击.
.C#3.0 中的扩展方法 (Extension .
.C#中水晶按钮的程序生成.
.如何获取当前操作系统的软件版本.
.用C#.NET实现拖放操作.
.用C#通过网址得到域名.
.C#下提取汉字首字的拼音首字母并.
.在C#中动态调用native dll的导出.
.如何用C#将数据库中的记录制成XML.
.Vsiaul C#如何读取注册信息.
..NET中多线程的同步资源访问.
.用C#实现FTP搜索引擎.
.C#-委托和事件.
.用Visual C#中实现DB2数据库编程.
.C#操作xml文件入门.
.用C#把文件转换为XML.
.C#控制Windows Messenger和Windo.

利用网页强制重启服务器(C#)

发表日期:2008-6-8


点击Button1,强制重启

C#重启服务器代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
namespace WebApplication1_advapi
{
    /**//// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
        protected const int SE_PRIVILEGE_ENABLED = 0x2;
        protected const int TOKEN_QUERY = 0x8;
        protected const int TOKEN_ADJUST_PRIVILEGES = 0x20;
        protected const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
        protected const int EWX_LOGOFF = 0x0;
        protected const int EWX_SHUTDOWN = 0x1;
        protected const int EWX_REBOOT = 0x2;
        protected const int EWX_FORCE = 0x4;
        protected const int EWX_POWEROFF = 0x8;
        protected System.Web.UI.WebControls.Button Button1;
        protected const int EWX_FORCEIFHUNG = 0x10;


        [StructLayout(LayoutKind.Sequential, Pack=1)]
            protected struct LuidStruct
        {
            public int Count;
            public long Luid;
            public int Attr;
        }

        [DllImport("kernel32.dll", ExactSpelling=true)]
        protected static extern IntPtr GetCurrentProcess();

        [DllImport("advapi32.dll", SetLastError=true)]
        protected static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

        [DllImport("advapi32.dll", SetLastError=true)]
        protected static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

        [DllImport("advapi32.dll", SetLastError=true, ExactSpelling=true)]
        protected static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref LuidStruct newst, int len, IntPtr prev, IntPtr relen);

        [DllImport("user32.dll", SetLastError=true, ExactSpelling=true)]
        protected static extern bool ExitWindowsEx(int flg, int rea);

        protected static void DoExitWindows(int flg)
        {
            LuidStruct tp;
            IntPtr hproc = GetCurrentProcess();
            IntPtr htok = IntPtr.Zero;

            OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
            tp.Count = 1;
            tp.Luid = 0;
            tp.Attr = SE_PRIVILEGE_ENABLED;
            LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
            AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
            ExitWindowsEx(flg, 0);
        }

        public static void Shutdown()
        {
            DoExitWindows(EWX_SHUTDOWN);
        }

        public static void Reboot()
        {
            DoExitWindows(EWX_REBOOT | EWX_FORCE);
        }

        public static void Logoff()
        {
            DoExitWindows(EWX_LOGOFF);
        }

        [DllImport("advapi32.dll", SetLastError=true, ExactSpelling=false)]
        protected static extern bool InitiateSystemShutdown(string name, string msg, int timeout, bool force, bool reboot);


        private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面

        }

        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
       
        /**//// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {   
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Button1_Click(object sender, System.EventArgs e)
        {
               InitiateSystemShutdown(null,null,0,true,true);
        }
    }
}

上一篇:关于VS 2008和.NET 3.5 Beta2新特性介绍 人气:2537
下一篇:在CS类文件里向调用页面输出Javascript代码的3种方法 人气:2808
浏览全部C#的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐