谁有用ExitWindowsEx关机的程序??

shyuan 2002-10-30 11:43:56
一直搞不定AdjustTokenPrivileges的优先级,谁能帮帮忙??多谢。
...全文
27 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Montaque 2003-04-07
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/TopicView1.asp?id=1153268
http://expert.csdn.net/Expert/TopicView1.asp?id=922105
kevincf 2003-04-07
  • 打赏
  • 举报
回复
up
night_elves 2003-01-24
  • 打赏
  • 举报
回复
不知还有没有人看...

楼上的,你那个错误是肯定的,你定义的TOKEN_PRIVILEGES里的Privileges会自己增加长度吗?你只是简单的把它的PrivilegeCount变成一,而Privileges还是nothing!也就是说这个mPriv.Privileges(0).Attributes根本就是不存在的!

不过,好象就算这里改对了,到最后一步还是有问题,研究中....
shyuan 2002-10-31
  • 打赏
  • 举报
回复
我运行到mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED时,发生NullReferenceException,谁能告诉我为什么?

Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private Const EWX_POWEROFF = 8
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const ANYSIZE_ARRAY = 1
Private Const VER_PLATFORM_WIN32_NT = 2

Structure LUID
Dim LowPart As Long
Dim HighPart As Long
End Structure
Structure LUID_AND_ATTRIBUTES
Dim pLuid As LUID
Dim Attributes As Long
End Structure
Structure TOKEN_PRIVILEGES
Dim PrivilegeCount As Long
Dim Privileges() As LUID_AND_ATTRIBUTES
End Structure

Private Sub EnableShutDown()
Dim hProc As Long
Dim hToken As Long
Dim mLUID As LUID
Dim mPriv As TOKEN_PRIVILEGES
Dim mNewPriv As TOKEN_PRIVILEGES
hProc = GetCurrentProcess()
OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken)
LookupPrivilegeValue("", "SeShutdownPrivilege", mLUID)
mPriv.PrivilegeCount = 1
mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED ''此处发生错误!!!
mPriv.Privileges(0).pLuid = mLUID
' enable shutdown privilege for the current application
AdjustTokenPrivileges(hToken, False, mPriv, 4 + (12 * mPriv.PrivilegeCount), mNewPriv, 4 + (12 * mNewPriv.PrivilegeCount))
End Sub
HellMaster 2002-10-30
  • 打赏
  • 举报
回复
你搜索一下.Net的帮助就可以找到示例了。
我把它贴出来了

HANDLE hToken;
TOKEN_PRIVILEGES tkp;

// Get a token for this process.

if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");

// Get the LUID for the shutdown privilege.

LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);

tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// Get the shutdown privilege for this process.

AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);

// Cannot test the return value of AdjustTokenPrivileges.

if (GetLastError() != ERROR_SUCCESS)
error("AdjustTokenPrivileges");

// Shut down the system and force all applications to close.

if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
error("ExitWindowsEx");
shyuan 2002-10-30
  • 打赏
  • 举报
回复
举个例子
visualcpu 2002-10-30
  • 打赏
  • 举报
回复
用WMI就可以了

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧