求一段ASP.NET技术设置一个按钮电脑就可以关机的代码,小生只会ASP.NET技术,VB什么都不会,

解决方案 »

  1.   

    using System; 
    using System.Runtime.InteropServices; 
       
    class shoutdown{ 
       [StructLayout(LayoutKind.Sequential, Pack=1)] 
       internal struct TokPriv1Luid 
       { 
          public int Count; 
          public long Luid; 
          public int Attr; 
       }    [DllImport("kernel32.dll", ExactSpelling=true) ] 
       internal static extern IntPtr GetCurrentProcess();    [DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ] 
       internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );    [DllImport("advapi32.dll", SetLastError=true) ] 
       internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );    [DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ] 
       internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall, 
    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );    [DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ] 
       internal static extern bool ExitWindowsEx( int flg, int rea );    internal const int SE_PRIVILEGE_ENABLED = 0x00000002; 
       internal const int TOKEN_QUERY = 0x00000008; 
       internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; 
       internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege"; 
       internal const int EWX_LOGOFF = 0x00000000; 
       internal const int EWX_SHUTDOWN = 0x00000001; 
       internal const int EWX_REBOOT = 0x00000002; 
       internal const int EWX_FORCE = 0x00000004; 
       internal const int EWX_POWEROFF = 0x00000008; 
       internal const int EWX_FORCEIFHUNG = 0x00000010;    private static void DoExitWin(int flg) 
       { 
          bool ok; 
          TokPriv1Luid tp; 
          IntPtr hproc = GetCurrentProcess(); 
          IntPtr htok = IntPtr.Zero; 
          ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok ); 
          tp.Count = 1; 
          tp.Luid = 0; 
          tp.Attr = SE_PRIVILEGE_ENABLED; 
          ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid ); 
          ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero ); 
          ok = ExitWindowsEx( flg, 0 ); 
       }       public static void Main() 
          { 
             Console.WriteLine("正在关机……"); 
             // 修改 EWX_SHUTDOWN 或者 EWX_LOGOFF, EWX_REBOOT等实现不同得功能。 
             // 在XP下可以看到帮助信息,以得到不同得参数 
             // SHUTDOWN /? 
             DoExitWin(EWX_SHUTDOWN); 
          } 

      

  2.   

    1楼的代码只能关服务器哦.如果要控制客户端,可以设计一个Activex,或下一下
      

  3.   

    运行shutdown -r -f -c "重新启动"shutdown -s -f -c "叫你关机"
      

  4.   

    应该做成activeX给客户端下载后,调用执行关机。但是一般会被用户的IE屏蔽掉,所以下载前要给用户提示。
      

  5.   

    一楼的api应该可以的另外用shutdown应该可以,你用代码执行cmd语句就可以了
    shutdown命令的语法格式如下:   shutdown [-i  -l -s  -r  -a] [-f] [-m [\\ComputerName]] [-t xx] [-c "message"] [-d[p]:xx:yy] 其中,各参数的含义为:   -i 显示图形界面的对话框。 
      -l 注销当前用户,这是默认设置。-m ComputerName 优先。 
      -s 关闭计算机。 
      -r 关闭之后重新启动。 
      -a 中止关闭。除了 -l 和 ComputerName 外,系统将忽略其它参数。在超时期间,您只可以使用 -a。 
      -f 强制运行要关闭的应用程序。 
      -m [\\ComputerName] 指定要关闭的计算机。 
      -t xx 将用于系统关闭的定时器设置为 xx 秒。默认值是 20 秒。 
      -c "message" 指定将在“系统关闭”窗口中的“消息”区域显示的消息。最多可以使用 127 个字符。引号中必须包含消息。   -d [p]:xx:yy 列出系统关闭的原因代码。
      

  6.   

    如果不用activeX那,我想做的功能是,我在网页上有一个按钮,如果我点了这个按钮之后,电脑会关机,
    就是说,当用 游览器游览我的网页的时候,没有安全阻拦,也不用什么安装什么,不知道这样可行不可行