#include #include #include #include int wmain(int argc,wchar_t **argv) { if(argc==4 && std::wstring_view(argv[1])==L"--hold") { const auto handle=CreateFileW(argv[2],GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,nullptr, OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,nullptr); if(handle==INVALID_HANDLE_VALUE) return 1; const auto ready=CreateFileW(argv[3],GENERIC_WRITE,FILE_SHARE_READ,nullptr,CREATE_ALWAYS,0,nullptr); if(ready==INVALID_HANDLE_VALUE){CloseHandle(handle);return 1;} CloseHandle(ready); Sleep(INFINITE); CloseHandle(handle); return 0; } // A launch through the embedded terminal would inherit its console. DWORD consoleProcesses[1]{}; if(GetConsoleProcessList(consoleProcesses,1)>1) return 1; wchar_t executable[32768]{}; const auto length=GetModuleFileNameW(nullptr,executable,static_cast(std::size(executable))); if(!length || length>=std::size(executable)) return 1; const std::filesystem::path target=argc==2?argv[1]:executable; auto report=target; report+=L".opened"; std::ofstream result(report,std::ios::binary); result<<"opened"; return result?0:1; }