一.关机
OSVERSIONINFO OsVersionInfo;//包含操作系统版本信息的数据结构
OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&OsVersioninfo);//获取操作系统版本信息
if(OsVersionInfo.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
{
//WINDOWS98,调用ExitWindowsEx()函数重新启动计算机
DWORD dwReserved;
ExitWindowsEx(EWX_REBOOT,dwReserved);//可以改变第一个参数,实现注销用户;
}
关于getversionex函数
根据OSVERSIONINFO的成员判断:
Windows 2000:dwMajorVersion=5 dwMinorVersion=0;
Windows XP: dwMajorVersion=5 dwMinorVersion=1
Windows Vista: dwMajorVersion=6;
二.重启
typedef int (CALLBACK *SHUTDOWNDLG)(int); //
显示关机对话框函数的指针
HINSTANCE hInst = LoadLibrary("shell32.dll"); //装入shell32.dll
SHUTDOWNDLG ShutDownDialog; //指向shell32.dll库中显示关机对话框函数的指针
if(hInst != NULL)
{
//获得函数的地址并调用之
ShutDownDialog = (SHUTDOWNDLG)GetProcAddress(hInst,(LPSTR)60);
(*ShutDownDialog)(0);
}
HINSTANCE hInst = LoadLibrary("shell32.dll"); //装入shell32.dll
SHUTDOWNDLG ShutDownDialog; //指向shell32.dll库中显示关机对话框函数的指针
if(hInst != NULL)
{
//获得函数的地址并调用之
ShutDownDialog = (SHUTDOWNDLG)GetProcAddress(hInst,(LPSTR)60);
(*ShutDownDialog)(0);
}