|
以前我用VC写的一个关机程序
通过调用NTDLL.DLL的“NtShutdownSystem”函数来关机的。
源码:
void CShutdownDlg::shut(int action)
{
HINSTANCE h=LoadLibrary("ntdll.dll");
if(!h)
{
MessageBox("加载'ntdll.dll'失败!");
return;
}
typedef int (__stdcall *AdjustPrivilege)(int,int,int,int *);
AdjustPrivilege SetPrivilege=NULL;
SetPrivilege=(AdjustPrivilege)GetProcAddress(h,"RtlAdjustPrivilege");
if(!SetPrivilege)
{
MessageBox("加载'RtlAdjustPrivilege'失败!");
return;
}
typedef int (__stdcall *ShutdownSystem)(int);
ShutdownSystem Shutdown=NULL;
Shutdown=(ShutdownSystem)GetProcAddress(h,"NtShutdownSystem");
if(!Shutdown)
{
MessageBox("加载'NtShutdownSystem'失败!");
return;
}
const int SE_SHUTDOWN_PRIVILEGE = 19;
const int shutdown = 0;
const int RESTART = 1;
const int POWEROFF = 2;
int *a;
a=new int;
(*SetPrivilege)(SE_SHUTDOWN_PRIVILEGE,true,false,a);
(*Shutdown)(action);
delete a;
}
用法:调用这个函数用参数shutdown,RESTART ,POWEROFF 来表示关机还是重启。
[ 本帖最后由 123 于 2007-1-13 05:56 PM 编辑 ] |
|