Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Access is denied error on Windows from not running as Administrator #30

Open
ShayBox opened this issue Dec 2, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@ShayBox
Copy link

ShayBox commented Dec 2, 2022

I'm trying to handle the windows error from MediaControls::new that it panics when the program isn't run as Administrator, but I don't see how to convert the error to a WindowsError, only from.

I also can't seem to use error-stack IntoReport on souvlaki errors like other errors, they don't implement std::error::Error.

The Administrator requirement may be from using the existing HWND created by the terminal when opening my program, because I don't spawn a window myself.

#[cfg(not(target_os = "windows"))]
let hwnd = None;

#[cfg(target_os = "windows")]
let hwnd = {
    use windows::Win32::System::Console::GetConsoleWindow;

    let console_window = unsafe { GetConsoleWindow() };
    let hwnd = console_window.0 as *mut c_void;
    Some(hwnd)
};

let platform_config = PlatformConfig {
    dbus_name: "VRC_OSC",
    display_name: "VRC-OSC",
    hwnd,
};

let controls = match MediaControls::new(platform_config) {
    Ok(controls) => controls,
    Err(error) => {
        // I can see the error code when printing but I can't access it
        println!("{:?}", error);
        panic!("{error:?}")
    }
};

EDIT: I can't seem to set_playback for sources other than my own with set_metadata, is it possible to do this?

@Sinono3
Copy link
Owner

Sinono3 commented Feb 4, 2023

As for the std::error::Error problem, I opened #32. Let me check the other.

@Sinono3
Copy link
Owner

Sinono3 commented Feb 4, 2023

I can't replicate the error. Access denied still pops up when I ran the code as administrator. Have you managed to get it working?

@ShayBox
Copy link
Author

ShayBox commented Feb 4, 2023

You have to run the compiled .exe directly, not through a terminal or editor, that allowed for using the HWND without access denied

@Sinono3 Sinono3 added the bug Something isn't working label Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants