1.关机代码
#include <iostream>
#include <cstdlib>
int main() {
// 立即关机
int result = system("shutdown -h now");
if (result != 0) {
std::cerr << "关机命令执行失败!" << std::endl;
}
return 0;
}
2.锁屏代码
#include <iostream>
#include <windows.h>
int main() {
if (LockWorkStation()) {
std::cout << "成功锁定工作站。" << std::endl;
} else {
std::cerr << "锁定工作站失败,错误代码: " << GetLastError() << std::endl;
}
return 0;
}