简单问题:怎样关闭计算机和重新启动系统? 怎样关闭计算机和重新启动系统?我用ExitWindowsEx(EWX_SHUTDOWN,0);ExitWindowsEx(EWX_REBOOT,0);都没有用。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试一下ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE,0);ExitWindowsEx(EWX_REBOOT|EWX_FORCE;,0); 在win98下可以ExitWindowsEx(EWX_SHUTDOWN |EWX_FORCE,NULL);就可以了,但是在win2000下这个关机的线程需要一定的权限才有用! 试试这个:(98 和 2000 下都可以的)// ExitW.cpp : Defines the entry point for the DLL application.//#include "stdafx.h"BOOL WINAPI IsWin2000 ();BOOL EnablePrivilege(LPTSTR privilege);BOOL DisablePrivilege(LPTSTR privilege);void WINAPI exitw(int flag);BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){ return TRUE;}void WINAPI exitw(int flag){ // flag // EWX_LOGOFF 0 // EWX_SHUTDOWN 1 // EWX_REBOOT 2 // EWX_POWEROFF 8 BOOL success; if(flag==EWX_LOGOFF) ExitWindowsEx(EWX_LOGOFF, 0); if(IsWin2000 ()) { BOOL retval = EnablePrivilege(SE_SHUTDOWN_NAME); if(!retval) return; } if(flag==EWX_REBOOT) success = ExitWindowsEx(EWX_REBOOT, 0); if(flag==EWX_POWEROFF) success = ExitWindowsEx(EWX_POWEROFF, 0); if(flag==EWX_SHUTDOWN) success = ExitWindowsEx(EWX_SHUTDOWN, 0); if(IsWin2000 ()) DisablePrivilege(SE_SHUTDOWN_NAME);}//=============================================================================BOOL EnablePrivilege(LPTSTR privilege){ BOOL success; HANDLE token; LUID luid; TOKEN_PRIVILEGES tokenPrivileges; // Get token for this process success = OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token); if (!success) { return FALSE; } // Gets the value for a privilege success = LookupPrivilegevalue(0, privilege, &luid); if (!success) { return FALSE; } // Enable the privilege tokenPrivileges.PrivilegeCount = 1; tokenPrivileges.Privileges[0].Luid = luid; tokenPrivileges.Privileges[0].Attributes =SE_PRIVILEGE_ENABLED; success = AdjustTokenPrivileges(token, FALSE,&tokenPrivileges, 0, 0, 0); // Always returns true, so check GetLastError if (GetLastError() != ERROR_SUCCESS) { return FALSE; } return TRUE;}BOOL DisablePrivilege(LPTSTR privilege){ BOOL success; HANDLE token; LUID luid; TOKEN_PRIVILEGES tokenPrivileges; // Get tokens for this process success = OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token); if (!success) { return FALSE; } // Gets the value for a privilege success = LookupPrivilegevalue(0, privilege, &luid); if (!success) { return FALSE; } // Disable the privilege tokenPrivileges.PrivilegeCount = 1; tokenPrivileges.Privileges[0].Luid = luid; // disable the privilege tokenPrivileges.Privileges[0].Attributes = 0; success = AdjustTokenPrivileges(token, FALSE,&tokenPrivileges, 0, 0, 0); // Always returns true, so... if (GetLastError() != ERROR_SUCCESS) { return FALSE; } return TRUE;}BOOL WINAPI IsWin2000 () { OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) { osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE; } switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: if ( osvi.dwMajorVersion >= 5 ) return TRUE; break; } return FALSE; } to:abigfrog(千年精灵)(PHP初学) LookupPrivilegevalue()这个函数的实现是什么? LookupPrivilegevalue是api,winbase.h中定义的 //重新启动 OSVERSIONINFO osv; osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO; GetVersionEx(&osv); if(osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { HANDLE hProcess,hToken; TOKEN_PRIVILEGES Privileges; LUID luid; hProcess=GetCurrentProcess(); OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken); Privileges.PrivilegeCount=1; LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid); Privileges.Privileges[0].Luid=luid; Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL); } ExitWindowsEx(EWX_REBOOT,0); 哪位大哥帮忙写个MFC程序? 初学多线程一个疑问 怎么让CListCtrl的Item永远不被选中 有关CptrList的RemoveAll()? 如何处理呢 问一个关于句柄和指针的问题!很菜的问题!帮帮忙啊! 急!!!一个对Access数据库的表中数据进行操作的问题!!(我的教c的博士老师也不会哦...高手来看看,解决的话,我的500分全送!!) 请教:在客户区显示图片,然后用鼠标拖动,结果发现闪烁现象,该如何解决,最好有实例,谢谢各位! MFC CListCtrl icon属性下,为图标加载图片 帮帮忙AVI是怎样的格式?我给100分谢谢! java是否真的跨平台 字符串操作(多谢高手)
试一下
ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE,0);
ExitWindowsEx(EWX_REBOOT|EWX_FORCE;,0);
ExitWindowsEx(EWX_SHUTDOWN |EWX_FORCE,NULL);就可以了,
但是在win2000下这个关机的线程需要一定的权限才有用!
//#include "stdafx.h"
BOOL WINAPI IsWin2000 ();
BOOL EnablePrivilege(LPTSTR privilege);
BOOL DisablePrivilege(LPTSTR privilege);
void WINAPI exitw(int flag);BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}void WINAPI exitw(int flag)
{
// flag
// EWX_LOGOFF 0
// EWX_SHUTDOWN 1
// EWX_REBOOT 2
// EWX_POWEROFF 8
BOOL success;
if(flag==EWX_LOGOFF) ExitWindowsEx(EWX_LOGOFF, 0); if(IsWin2000 ())
{
BOOL retval = EnablePrivilege(SE_SHUTDOWN_NAME);
if(!retval) return;
} if(flag==EWX_REBOOT) success = ExitWindowsEx(EWX_REBOOT, 0);
if(flag==EWX_POWEROFF) success = ExitWindowsEx(EWX_POWEROFF, 0);
if(flag==EWX_SHUTDOWN) success = ExitWindowsEx(EWX_SHUTDOWN, 0);
if(IsWin2000 ()) DisablePrivilege(SE_SHUTDOWN_NAME);
}//=============================================================================
BOOL EnablePrivilege(LPTSTR privilege)
{
BOOL success;
HANDLE token;
LUID luid;
TOKEN_PRIVILEGES tokenPrivileges; // Get token for this process
success = OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token);
if (!success)
{
return FALSE;
} // Gets the value for a privilege
success = LookupPrivilegevalue(0, privilege, &luid);
if (!success)
{
return FALSE;
}
// Enable the privilege
tokenPrivileges.PrivilegeCount = 1;
tokenPrivileges.Privileges[0].Luid = luid;
tokenPrivileges.Privileges[0].Attributes =SE_PRIVILEGE_ENABLED;
success = AdjustTokenPrivileges(token, FALSE,&tokenPrivileges, 0, 0, 0);
// Always returns true, so check GetLastError
if (GetLastError() != ERROR_SUCCESS)
{
return FALSE;
}
return TRUE;
}BOOL DisablePrivilege(LPTSTR privilege)
{
BOOL success;
HANDLE token;
LUID luid;
TOKEN_PRIVILEGES tokenPrivileges; // Get tokens for this process
success = OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token);
if (!success)
{
return FALSE;
} // Gets the value for a privilege
success = LookupPrivilegevalue(0, privilege, &luid);
if (!success)
{
return FALSE;
} // Disable the privilege
tokenPrivileges.PrivilegeCount = 1;
tokenPrivileges.Privileges[0].Luid = luid; // disable the privilege
tokenPrivileges.Privileges[0].Attributes = 0;
success = AdjustTokenPrivileges(token, FALSE,&tokenPrivileges, 0, 0, 0); // Always returns true, so...
if (GetLastError() != ERROR_SUCCESS)
{
return FALSE;
}
return TRUE;
}BOOL WINAPI IsWin2000 ()
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
{
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE;
}
switch (osvi.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
if ( osvi.dwMajorVersion >= 5 ) return TRUE;
break;
}
return FALSE;
}
LookupPrivilegevalue()这个函数的实现是什么?
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
GetVersionEx(&osv);
if(osv.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
HANDLE hProcess,hToken;
TOKEN_PRIVILEGES Privileges;
LUID luid;
hProcess=GetCurrentProcess();
OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
Privileges.PrivilegeCount=1;
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
Privileges.Privileges[0].Luid=luid;
Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);
}
ExitWindowsEx(EWX_REBOOT,0);