网页功能: 加入收藏 设为首页 网站搜索  
在WIN2000下实现程序的关机
发表日期:2002-06-27作者:李立华[原创] 出处:  

在Win2000下比较难用,你还要获得系统权限的

你须要引用下面的API

Public Const EWX_FORCE = 4

Public Const TOKEN_ADJUST_PRIVILEGES = &H20

Public Const TOKEN_QUERY = &H8

Public Const SE_PRIVILEGE_ENABLED = &H2

Public Const ANYSIZE_ARRAY = 1

Type LUID

  lowpart As Long

  highpart As Long

End Type

Type LUID_AND_ATTRIBUTES

  pLuid As LUID

  Attributes As Long

End Type

Type TOKEN_PRIVILEGES

  PrivilegeCount As Long

  Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES

End Type

Declare Function GetCurrentProcess Lib "kernel32" () As Long

Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long

Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long

Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long

Sub AdjustTokenPrivilegesForNT()

  Dim hdlProcessHandle As Long

  Dim hdlTokenHandle As Long

  Dim tmpLuid As LUID

  Dim tkp As TOKEN_PRIVILEGES

  Dim tkpNewButIgnored As TOKEN_PRIVILEGES

  Dim lBufferNeeded As Long

 

  hdlProcessHandle = GetCurrentProcess()

  OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _

           TOKEN_QUERY), hdlTokenHandle

  LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid

  tkp.PrivilegeCount = 1

  tkp.Privileges(0).pLuid = tmpLuid

  tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED

  AdjustTokenPrivileges hdlTokenHandle, False, tkp, _

             Len(tkpNewButIgnored), tkpNewButIgnored, _

             lBufferNeeded

End Sub

关机时用下面的代码

  AdjustTokenPrivilegesForNT

  ExitWindowsEx uFlags, 0

 

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 在WIN2000下实现程序的关机
本类热点文章
  揭穿号称内存占用极低的软件的诡计
  用VB6实现真正实用的多线程处理
  读写INI文件的四个函数
  shell函数能以同步方式打开一个exe文件
  VB的API编程精粹
  TAPI笔记
  锁定计算机
  巧用API函数增强VB位操作功能
  在VB中使用API函数
  让你的文本框“聪明”一点
  关机消息的拦截
  在WIN2000下实现程序的关机
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2019 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.00474