C语言之类的关机程序
答案:3 悬赏:50 手机版
解决时间 2021-05-07 16:39
- 提问者网友:寂寞梧桐
- 2021-05-07 06:14
帮我写个简单的定时关机程序 ,我要把他放在开机启动项目中,来控制孩子玩电脑游戏。 例如 点“ 开始” 在 “运行”里输入 “Shutdown.exe -s -t 3600”之类的就可以了 。
最佳答案
- 五星知识达人网友:纵马山川剑自提
- 2021-05-07 06:58
同志,你好,试试用API吧,需要对进程进行提权,具体看代码吧!
#include
void main()
{
HANDLE hProcessHandle;
HANDLE hTokenHandle;
LUID tmpLuid;
TOKEN_PRIVILEGES tkpNew;
TOKEN_PRIVILEGES tkpPrevious;
long lBufferNeeded;
hProcessHandle = GetCurrentProcess();
OpenProcessToken(hProcessHandle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, hTokenHandle);
LookupPrivilegeValue(" ", "SeShutdownPrivilege ", &tmpLuid);
tkpNew.PrivilegeCount = 1;
tkpNew.Privileges.Luid = tmpLuid;
tkpNew.Privileges.Attributes = SE_PRIVILEGE_ENABLED;
lBufferNeeded = 0;
AdjustTokenPrivileges(hTokenHandle, false, tkpNew, sizeof(tkpPrevious), tkpPrevious, lBufferNeeded);
ExitWindowsEx(EWX_SHUTDOWN,0);
}
#include
void main()
{
HANDLE hProcessHandle;
HANDLE hTokenHandle;
LUID tmpLuid;
TOKEN_PRIVILEGES tkpNew;
TOKEN_PRIVILEGES tkpPrevious;
long lBufferNeeded;
hProcessHandle = GetCurrentProcess();
OpenProcessToken(hProcessHandle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, hTokenHandle);
LookupPrivilegeValue(" ", "SeShutdownPrivilege ", &tmpLuid);
tkpNew.PrivilegeCount = 1;
tkpNew.Privileges.Luid = tmpLuid;
tkpNew.Privileges.Attributes = SE_PRIVILEGE_ENABLED;
lBufferNeeded = 0;
AdjustTokenPrivileges(hTokenHandle, false, tkpNew, sizeof(tkpPrevious), tkpPrevious, lBufferNeeded);
ExitWindowsEx(EWX_SHUTDOWN,0);
}
全部回答
- 1楼网友:何以畏孤独
- 2021-05-07 08:15
main()
{system("shutdown -s -t 600");
}
注:-s为关机 -r为重启 -f为注销 -t后面为你限制的时间(秒)
- 2楼网友:轻雾山林
- 2021-05-07 07:17
加K8编程小组Q群一起深入学习吧
system("Shutdown.exe -s -t 3600");
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯