搜索墙首页  编程技术  java  asp  ajax  php  c/c#/c++  数据库  oracle  mysql  db2  操作系统  windows  linux  股吧
首页 > 编程 > asp.net
 1         
1楼  ai19811125 2007-11-03 08:44:00

如题.
2楼  lengfeng8866 2007-11-03 08:53:55

我帮你baidu了一下,http://blog.csdn.net/LoveNa/archive/2006/11/15/1385975.aspx的博客里有代码:
具体代码如下所示:

using  System; 
using  System.Runtime.InteropServices; 
   
namespace  MDINew 

   
public  class  MDI

  [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; 
   
  public  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  void  Reboot() 
  { 
  DoExitWin(  EWX_REBOOT  ); 
  } 
   



不过,我觉得直接创建一个进程调用shutdown -s -t 0 应该也可以吧?不过可能不安全。。没有试过,有机会我试试。
 1         
您的发言将按有关规定都会存档,您须为所发表后果负责,请您遵纪守法并注意语言文明。
标题:有知道.net关机代码的同仁,给提供一下关机代码,谢谢
热门关注
标题回复点击
Web.config文件里 <providerOption name="CompilerVersion" value="v3.5"/> 不允许有子节9569
100分 请教一问题,各位达人帮忙(帮顶给分)99474
js技巧收集(200多个) 看看看看!!!63438
准备离职了,我不知道怎么跟经理谈。大家给点意见吧?谢谢大家。62435
无法在此路径使用此配置节。当站点管理员使用继承的配置文件中的 <location allowOverride="false"> 锁定对此节的访问时会出现这种情况2415
【散分】Javascript 新年快乐(2),喜迎2010100408
请问大家"这是预编译工具生成的标记文件,不应被删除"的问题怎么解决?0395
链接服务器 "(null)" 的 OLE DB 访问接口 "Microsoft.Jet.OLEDB.4.0" 报错3383
ASP.NET热点问题解答14个61365
安装VS2005 出错 错误 1335,安装所需的 CAB 文件 XXX 已损坏?4362
搜索墙@2009 www.pkwall.com all rights reserved QQ:276471788 [京ICP备09111534号]
声明:本站部分数据来源于网络,仅供参考,如有版权问题,请联系我们,我们将及时删除!转载本站请注明来源