win32 fixes
All checks were successful
BlockStorage/repertory_mac/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-09-07 11:57:26 -07:00
parent 7fd518a1e5
commit 68ca817fd7
7 changed files with 33 additions and 12 deletions

View File

@@ -23,6 +23,7 @@
#include "utils/windows.hpp"
#include "utils/com_init_wrapper.hpp"
#include "utils/error.hpp"
#include "utils/file.hpp"
#include "utils/path.hpp"
@@ -91,10 +92,11 @@ auto is_process_elevated() -> bool {
auto ret{false};
HANDLE token{INVALID_HANDLE_VALUE};
if (::OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) {
TOKEN_ELEVATION te{};
DWORD sz = sizeof(te);
if (::GetTokenInformation(token, TokenElevation, &te, sizeof(te), &sz)) {
ret = (te.TokenIsElevated != 0);
TOKEN_ELEVATION token_elevation{};
DWORD size = sizeof(token_elevation);
if (::GetTokenInformation(token, TokenElevation, &token_elevation,
sizeof(token_elevation), &size)) {
ret = (token_elevation.TokenIsElevated != 0);
}
}
@@ -141,6 +143,8 @@ auto run_process_elevated(std::vector<const char *> args) -> int {
void set_last_error_code(DWORD error_code) { ::SetLastError(error_code); }
auto get_startup_folder() -> std::wstring {
utils::com_init_wrapper wrapper;
PWSTR raw{nullptr};
auto result = ::SHGetKnownFolderPath(FOLDERID_Startup, 0, nullptr, &raw);
if (FAILED(result)) {
@@ -159,10 +163,12 @@ auto get_startup_folder() -> std::wstring {
auto create_shortcut(const shortcut_cfg &cfg, bool overwrite_existing) -> bool {
REPERTORY_USES_FUNCTION_NAME();
const auto hr_hex = [](HRESULT hr) -> std::string {
utils::com_init_wrapper wrapper;
const auto hr_hex = [](HRESULT result) -> std::string {
std::ostringstream oss;
oss << "0x" << std::uppercase << std::hex << std::setw(8)
<< std::setfill('0') << static_cast<std::uint32_t>(hr);
<< std::setfill('0') << static_cast<std::uint32_t>(result);
return oss.str();
};
@@ -191,8 +197,8 @@ auto create_shortcut(const shortcut_cfg &cfg, bool overwrite_existing) -> bool {
}
IShellLinkW *psl{nullptr};
HRESULT result = ::CoCreateInstance(CLSID_ShellLink, nullptr,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
auto result = ::CoCreateInstance(CLSID_ShellLink, nullptr,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
if (FAILED(result)) {
utils::error::handle_error(
function_name,