社区
VB
帖子详情
想实现API函数ExitWindowsEx的功能,使用.NET framework提供的东东怎样去解决?(内空)
RongX
2002-07-17 04:30:38
如标题
...全文
41
2
打赏
收藏
想实现API函数ExitWindowsEx的功能,使用.NET framework提供的东东怎样去解决?(内空)
如标题
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
GuoKing
2002-07-18
打赏
举报
回复
好复杂!!!
freesoul_ms
2002-07-17
打赏
举报
回复
感谢您使用微软产品。
您可以使用Win32 API直接调用AdjustTokenPrivileges和ExitWindowsEx:
using System.Runtime.InteropServices;
//以下代码添加到类声明的后面:
[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 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 );
}
使用方法:
DoExitWin( EWX_POWEROFF );
希望能对您有所帮助!
======================
- 微软全球技术中心
本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能
带来的风险。具体事项可参见使用条
款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调
查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))
。
======================
截获
Ex
it
Windows
Ex
函数
调用
VC下DLL编程,截获
Ex
it
Windows
Ex
函数
调用,禁止关机
VB
.net
实现
定时关机
这是一个调用系统关机的程序,该程序可以定时关机地,倒计时关机,以及关机取消。代码齐全易懂。
VBA中
API
函数
集锦
API
函数
在 VB 中得到了充分的运用,同时也让无数 VB 爱好者沉溺于其中。幸运的是 Office
使用
的 VBA 也能很好的引入
API
函数
注销,关闭.重启计算机的
实现
(VB
.NET
源码)
注销,关闭.重启计算机注销,关闭.重启计算机注销,关闭.重启计算机
API
函数
详细详细介绍
chm文件,可更好的阅读和管理
Windows
API
函数
。
本手册中的
Windows
API
函数
大约有774个,共分十二大类,基本上包括了大部分的常用和非常用的
Windows
API
函数
。
VB
16,722
社区成员
110,526
社区内容
发帖
与我相关
我的任务
VB
VB技术相关讨论,主要为经典vb,即VB6.0
复制链接
扫一扫
分享
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章