如何用vc实现win2000系统重启,(小女子请教大内高手,超急在线等)

zenithgf 2003-10-31 11:55:59
附源码:

OSVERSIONINFO OsVersionInfo;//包含操作系统版本信息的数据结构 OsVersionInfo.dwOSVersionInfoSize= sizeof(OSVERSIONINFO);
OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&OsVersionInfo);//获取操作系统版本信息
if( OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
//Windows2000,调用ExitWindowsEx()函数重新启动计算机
::ExitWindowsEx(EWX_REBOOT,0);
}

}

好像还需要AdjustTokenPrivileges()但不知怎么用?请教高手。

...全文
42 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
pearpeach 2003-12-16
  • 打赏
  • 举报
回复
心理作用
fashion1840 2003-12-16
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2365/2365863.xml?temp=.5223352
http://expert.csdn.net/Expert/topic/2237/2237392.xml?temp=7.317752E-02
http://expert.csdn.net/Expert/topic/2217/2217602.xml?temp=.8936731
csgo 2003-12-11
  • 打赏
  • 举报
回复
假男人
zhan_yonghua 2003-12-10
  • 打赏
  • 举报
回复
小女子,怎么不结贴???
lxh49 2003-11-28
  • 打赏
  • 举报
回复
(小女子请教大内高手,超急在线等)为什么加这一句话?感觉在卖!
dennis80 2003-11-28
  • 打赏
  • 举报
回复
没必要啊
mahatma_cn 2003-11-27
  • 打赏
  • 举报
回复
没有必要申明自己是小女子吧,你看,引来一群“有颜色的狼”
syongzhang 2003-11-22
  • 打赏
  • 举报
回复
一群色狼
zhan_yonghua 2003-11-18
  • 打赏
  • 举报
回复
呵呵,建议几个大家提问都以MM贯名~~~~``^_^
fificake1 2003-11-18
  • 打赏
  • 举报
回复
我是mm,可为何不回答????
wuyulan 2003-11-14
  • 打赏
  • 举报
回复

就是
我也装MM
怀疑楼主也是呢
mingcedar 2003-11-14
  • 打赏
  • 举报
回复
还是MM的问题回答的人多,下回我也要用MM提问了 :)
ustbzbing 2003-11-14
  • 打赏
  • 举报
回复
ExitWindowEx(eWX_REBOOT,0)
armstrong2k 2003-11-13
  • 打赏
  • 举报
回复
如然,不同反响,这就是MM效应啊!
上面的MM你有福了!

Saimen(★天大地大※何处是我家★) 大哥的直接贴上去就可以了。
我刚做过这一段代码

fashion1840 2003-11-09
  • 打赏
  • 举报
回复
如然,不同反响,这就是MM效应啊!
上面的MM你有福了!
我就不多说了!同意saimen的,比较好!
qj7979 2003-11-04
  • 打赏
  • 举报
回复
BOOL InitiateSystemShutdown(
LPTSTR lpMachineName, // computer name
LPTSTR lpMessage, // message to display
DWORD dwTimeout, // length of time to display
BOOL bForceAppsClosed, // force closed option
BOOL bRebootAfterShutdown // reboot option
);
InitiateSystemShutdown(
NULL, // shut down local computer
"Click on the main window and press \
the Escape key to cancel shutdown.", // message to user
20, // time-out period
FALSE, // ask user to close apps
TRUE);
MSDN中有很详细的说明!
jijuzheng 2003-11-01
  • 打赏
  • 举报
回复
哇,是个MM哟
可惜哥哥我来晚了,都被楼上那帮色狼回答了

Windows NT/2000/XP: The following example enables the SE_SHUTDOWN_NAME privilege and then shuts down the system.

HANDLE hToken;
TOKEN_PRIVILEGES tkp;

// Get a token for this process.

if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");

// Get the LUID for the shutdown privilege.

LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);

tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// Get the shutdown privilege for this process.

AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);

// Cannot test the return value of AdjustTokenPrivileges.

if (GetLastError() != ERROR_SUCCESS)
error("AdjustTokenPrivileges");

// Shut down the system and force all applications to close.

if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
error("ExitWindowsEx");
For more information about setting security privileges, see Privileges.


HuWenjin 2003-11-01
  • 打赏
  • 举报
回复
用下面的



void CCMPCtrlDlg::ShutDownComputer()
{
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure

if( !OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
&hToken) )
{
// 说明运行于98模式下
if( ExitWindowsEx(EWX_SHUTDOWN,0) != 0 )
EndDialog(IDOK);

return;
}

// Get the LUID for shutdown privilege.

LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);

tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// Get shutdown privilege for this process.

AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);

//
// The return value of AdjustTokenPrivileges can't be tested
//
if (GetLastError() != ERROR_SUCCESS)
{
MessageBox("Adjuste error! ");
return;
}

//if( ExitWindowsEx(EWX_POWEROFF,0) == 0 ) //关机
if( ExitWindowsEx(EWX_REBOOT,0) == 0 ) //重起

return;
else
EndDialog(IDOK);
}
BlueOrder 2003-11-01
  • 打赏
  • 举报
回复
::ExitWindowEx()就可以啦!!!
yintongshun 2003-10-31
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2365/2365863.xml?temp=.5223352
http://expert.csdn.net/Expert/topic/2237/2237392.xml?temp=7.317752E-02
http://expert.csdn.net/Expert/topic/2217/2217602.xml?temp=.8936731
加载更多回复(6)

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧