社区
VB
帖子详情
想实现API函数ExitWindowsEx的功能,使用.NET framework提供的东东怎样去解决?(内空)
RongX
2002-07-17 04:30:38
如标题
...全文
40
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
`
函数
调用,从而
实现
禁止关机的
功能
。DLL编程是一种高效且灵活的方法,允许我们插入代码到其他程序中,而无需修改它们的源代码。 ...
VB
.net
实现
定时关机
在VB
.NET
编程环境中,
实现
定时关机
功能
主要涉及到
Windows
API
调用,这是由于
.NET
Framework
本身并不
提供
直接的关机或重启系统的方法。本程序通过调用
Windows
API
函数
来
实现
这一目标,具体包括设置定时器、处理用户...
VBA中
API
函数
集锦
如果我们
想
要强制关闭计算机,可以
使用
API
函数
`
Ex
it
Windows
Ex
`: `Declare Function
Ex
it
Windows
Ex
Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long` 然后,我们可以
使用
以下代码来...
注销,关闭.重启计算机的
实现
(VB
.NET
源码)
在VB
.NET
编程环境中,我们可以利用内置的
Windows
API
函数
或者
.NET
Framework
提供
的System.Diagnostics命名空间中的Process类来
实现
注销、关闭和重启计算机的
功能
。这些操作对于系统管理员或者开发系统控制软件的...
API
函数
详细详细介绍
该资源涵盖了大约774个
API
函数
,这些
函数
被分类为十二大类别,确保了对
Windows
API
的广泛覆盖,无论你是初学者还是经验丰富的开发者,都能从中找到你需要的信息。下面我们将深入探讨其中的一些关键知识点: 1. **...
VB
16,722
社区成员
110,526
社区内容
发帖
与我相关
我的任务
VB
VB技术相关讨论,主要为经典vb,即VB6.0
复制链接
扫一扫
分享
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章