Your code is running
on the server.
Even if you did manage to get it working, all you would capture would be a screenshot of
the server's screen. Which would most likely be sat at the lock screen or login prompt, since you don't normally leave servers logged in.
If you want to capture all or part of
the user's screen, you'll have to use Javascript:
Using the Screen Capture API - Web APIs | MDN[
^]
And before you ask: no, there is no way around the prompt for permission, and there is no way to force the user to grant you permission. If there were, it would be a massive security vulnerability.
Edit: As I told you
last time you asked this exact question[
^].
Posting the same question over and over again is not going to change the answer. And it will potentially get you kicked off the site.