社区
VB
帖子详情
想实现API函数ExitWindowsEx的功能,使用.NET framework提供的东东怎样去解决?(内空)
RongX
2002-07-17 04:30:38
如标题
...全文
38
2
打赏
收藏
想实现API函数ExitWindowsEx的功能,使用.NET framework提供的东东怎样去解决?(内空)
如标题
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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))
。
======================
API
之网络
函数
---整理网络
函数
及
功能
API
之网络
函数
1.
API
之网络
函数
WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同一个网络资源的连接 WNetCancelConnection 结束一...
截获
Ex
it
Windows
Ex
函数
调用
VC下DLL编程,截获
Ex
it
Windows
Ex
函数
调用,禁止关机
一个自动关闭、重启计算机的例程
一个自动关闭、重启计算机的例程,用
API
函数
Ex
it
Windows
Ex
()
实现
。运行前先用regsvr32注册gif89.dll。
易语言
API
定时关机
易语言
API
定时关机源码,
API
定时关机,保存设置
函数
,读取设置
函数
,关机计时
函数
,获取进程关机权限,高级延时,
Ex
it
Windows
Ex
,CloseHandle,GetCurrentProcess,OpenProcessToken,LookupPrivilegeValue,...
MyFll Microsoft Visual FoxPro设计的扩展库
MyFll是专为Microsoft Visual FoxPro设计的扩展库,部分
函数
来自任明汉(RMH myF1论坛)前辈
提供
的myDll代码翻译而成,由于很多
功能
利用VFP处理比较烦锁,或无法
实现
,
使用
此库可有效
解决
VFP的弱项。部分与Win32
Api
...
VB
16,555
社区成员
110,528
社区内容
发帖
与我相关
我的任务
VB
VB技术相关讨论,主要为经典vb,即VB6.0
复制链接
扫一扫
分享
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章