nashaofu / xcap

XCap is a cross-platform screen capture library written in Rust. It supports Linux (X11, Wayland), MacOS, and Windows. XCap supports screenshot and video recording (to be implemented).
https://docs.rs/xcap
Apache License 2.0
491 stars 58 forks source link

Access is denied #152

Open louis030195 opened 2 months ago

louis030195 commented 2 months ago
image

do you have any idea how to fix this?

running as admin does not fix the error, also tried to tweak windows defender settings

i'm trying to see if windows require permission on newer versions, could it be?

louis030195 commented 2 months ago
image

139

same error (maybe)

louis030195 commented 2 months ago

wonder if its related to windows registry in any way

louis030195 commented 2 months ago

fyi i use xcap in a tauri app and by running the app in admin it solves the issue (kinda annoying, wonder if there is alternative way to do this)

louis030195 commented 2 months ago

nvm: user is getting these errors even with admin

nashaofu commented 2 months ago

Can you provide a sample code?

louis030195 commented 2 months ago

atm this is the code: https://github.com/mediar-ai/screenpipe/blob/main/screenpipe-vision/src/capture_screenshot_by_window.rs

@m13v can you help? can we create a code that reproduce this error?

nashaofu commented 2 months ago

This should only output logs to the console and should not cause a crash. If your program does not depend on app_name, theoretically, it should not be affected.

louis030195 commented 1 month ago

@nashaofu not sure to understand, do you know any way not to require admin right to use xcap on windows? happy to contribute anything

PS: $100 bounty for this fix

louis030195 commented 2 weeks ago

@nashaofu i think this occurs when there is window like task manager open and the app is not able to capture it due to elevated permission requirement

louis030195 commented 2 weeks ago

this is what claude suggest:

// ... existing imports ...
use windows::Win32::UI::WindowsAndMessaging::{GetWindowLongW, GWL_EXSTYLE, WS_EX_TOPMOST};

// ... existing code ...

#[cfg(target_os = "windows")]
fn is_window_elevated(window: &Window) -> bool {
    unsafe {
        let hwnd = window.hwnd() as isize;
        let ex_style = GetWindowLongW(hwnd, GWL_EXSTYLE);
        (ex_style & WS_EX_TOPMOST.0 as i32) != 0
    }
}

#[cfg(not(target_os = "windows"))]
fn is_window_elevated(_window: &Window) -> bool {
    false
}

// ... rest of the file ...
louis030195 commented 2 weeks ago

if this is true, i'd suggest having a propery is_elevated or similar so people can filter out if they want