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

PowerToys Run Calculator Click to 'Copy this number to clipboard' fails, with error dialogue #25437

Open
robfromnz opened this issue Apr 12, 2023 · 27 comments
Labels
Issue-Bug Something isn't working Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. Product-PowerToys Run Improved app launch PT Run (Win+R) Window Run-Plugin Things that relate with PowerToys Run's plugin interface

Comments

@robfromnz
Copy link

Microsoft PowerToys version

0.69.0

Installation method

GitHub

Running as admin

No

Area(s) with issue?

PowerToys Run

Steps to reproduce

Type a calculation into Run, eg "1+1".
Result is given with an option to click to copy:
image

Clicking to copy to causes the program to freeze, then throws up an error dialogue box.
image

✔️ Expected Behavior

Calculation result is copied to clipboard

❌ Actual Behavior

Calculation result is NOT copied to clipboard, error given instead:
image

Other Software

No response

@robfromnz robfromnz added Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Apr 12, 2023
@QantumEntangled
Copy link

I have been having the same issue for a few months on multiple Windows 10 machines.

PowerToysReport_2023-05-24-10-38-18.zip

@davidegiacometti davidegiacometti added Product-PowerToys Run Improved app launch PT Run (Win+R) Window Run-Plugin Things that relate with PowerToys Run's plugin interface labels Sep 11, 2023
@davidegiacometti
Copy link
Collaborator

xref #13024 (comment)

@x-lad
Copy link

x-lad commented Sep 11, 2023

same issue. i have admin on

@TheJoeFin
Copy link
Collaborator

/bugreport

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Sep 22, 2023
@microsoft-github-policy-service
Copy link
Contributor

Hi there!

We need a bit more information to really debug this issue. Can you add a "Report Bug" zip file here? You right click on our system tray icon and just go to report bug. Then drag the zipfile from your desktop onto the GitHub comment box in this issue. Thanks!
Report Bug

@microsoft-github-policy-service microsoft-github-policy-service bot added the Status-No recent activity no activity in the past 5 days when follow up's are needed label Sep 27, 2023
@coder543
Copy link

coder543 commented Oct 2, 2023

I personally ran into this issue this morning.

Stalebots are counterproductive. This is a very real issue, as confirmed by multiple people in this thread. The lack of response from the original author is irrelevant. Closing issues automatically like this only serves to obscure the actual bugs that software has.

@davidegiacometti can the stalebot be disabled for this issue? (or the whole repo..)

Regarding the xref above, I do not have Ditto installed. I have tried closing any software that seems like it might interact with the clipboard, but the issue persists.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Status-No recent activity no activity in the past 5 days when follow up's are needed label Oct 2, 2023
@Marc-Anderson
Copy link

Marc-Anderson commented Oct 4, 2023

same issue, adding that if you press enter(to copy), wait 1-2 seconds after the popup, and then press enter again it copies the result as expected and closes the popup.
PowerToysReport_2023-10-04-10-39-01.zip

@microsoft-github-policy-service microsoft-github-policy-service bot added the Status-No recent activity no activity in the past 5 days when follow up's are needed label Oct 9, 2023
@davidegiacometti davidegiacometti added Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Status-No recent activity no activity in the past 5 days when follow up's are needed labels Oct 9, 2023
@davidegiacometti
Copy link
Collaborator

It has also absolutely had the required zips uploaded. The bot is broken.

Yeah! I have updated the labels so the bot shouldn't bother anymore.

@ilsubyeega
Copy link

ilsubyeega commented Oct 18, 2023

I've quickly tested via this code and for me, it was Parsec that locked the clipboard that made fail from powertoys run.
Quitting parsec via the tray icon solved this issue.

Here's the code for whoever wants to test it:

using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ClipboardTester
{
    internal class Program
    {
        // https://stackoverflow.com/questions/6583642/determine-which-process-is-locking-the-clipboard
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr GetOpenClipboardWindow();

        [DllImport("user32.dll", SetLastError = true)]
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
        static void Main(string[] args)
        {
            while (true)
            {
                int processId;
                GetWindowThreadProcessId(GetOpenClipboardWindow(), out processId);

                var process = Process.GetProcessById(processId);
                Console.WriteLine($"Process name: {process.ProcessName} ({processId})");
                Thread.Sleep(50);
            }
        }
    }
}

Update) this issue persists even the svchost is holding the clipboard, dunno where to solve, maybe windows bug?

@Frenagon
Copy link

Frenagon commented Dec 5, 2023

I've been experiencing this issue for a while as well.
PowerToysReport_2023-12-04-20-57-44.zip

@x-lad
Copy link

x-lad commented May 25, 2024

same issue.
Does anyone have a solution?

report file here:
Uploading PowerToysReport_2024-05-27-15-01-40.zip…

@cwuom
Copy link

cwuom commented Jun 1, 2024

same issue.

PowerToysReport_2024-06-01-09-07-50.zip

@Chocolateandmilkwin
Copy link

Same issue can confirm that closing parsec stops the error.

@umarbutler
Copy link

+1

@umarbutler
Copy link

I don't have Parsec installed but also have this issue...

@TheJoeFin
Copy link
Collaborator

@umarbutler this is an issue where another program takes control of the clipboard and Windows does not allow other programs to interact with it. While this degrades the experience on PowerToys this is ultimately an issue with Windows and the architecture of the clipboard API.

As earlier comments have made clear PowerToys can only really highlight which program is abusing the API so the user can take action as they see fit.

@coder543
Copy link

coder543 commented Aug 1, 2024

@TheJoeFin I’ve never once seen any program other than PowerToys fail to copy something to the clipboard on Windows, which makes me skeptical that the problem truly is with Windows, and not with PowerToys.

I have also encountered this error dialog even when I’m not running anything that could possibly be interacting with the clipboard, as I mentioned in an earlier comment. I haven’t personally run into this as much lately, but that’s probably more of a result of changing how I use my computer than anything, but I’m still subscribed to this thread, and I don’t think this issue is so easily dismissed.

@TheJoeFin
Copy link
Collaborator

@coder543 that's fair, I would guess we have more than one issue going on here. Adding code like this comment linked below might help figure out the conflicts vs other bugs.
#25437 (comment)

Have you gone though any of the bug reports and found anything which might indicate what is going on other than conflicting with the clipboard API?

@Chocolateandmilkwin
Copy link

@coder543, the thing is that it does not fail to copy to the clipboard (at least in my case) it just shows the error.
Suppressing the error would solve all my problems.

@QantumEntangled
Copy link

I've been experiencing this issue for over a year now. It would be really helpful to have the option to suppress these error messages about the clipboard, so they don't pop up at all. Especially because the copy-to-clipboard actually is working properly.

I don't know if everyone else is having the same experience, but it's INCREDIBLY annoying getting an error pop-up that says something isn't working, when it is, in-fact, working flawlessly.

@TheJoeFin
Copy link
Collaborator

The lack of errors in the bugreports makes sense when there is no error and just an annoying message box being shown when it shouldn't.

@GhostVaibhav
Copy link
Contributor

Hi @TheJoeFin, I looked into the logs and in the last 2 log reports, I found the same 2 exceptions with the same 2 applications -

image

I think this is triggering the block below, and hence, displaying the dialog -

image

@josefblaha
Copy link

I was investigating this issue on my local. Here's what I found so far.

Exception

The ExternalException being thrown looks like this:

{"Module OpenClipboard failed (0x800401D0 (CLIPBRD_E_CANT_OPEN))"}
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
   at System.Windows.Clipboard.Flush()
   at Microsoft.PowerToys.Run.Plugin.Calculator.ResultHelper.<>c__DisplayClass2_0.<Action>b__0() in D:\Documents\PowerToys\src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.Calculator\ResultHelper.cs:line 50

The clipboard is a global resource in Windows, shared by all applications. Only one app at a time can access it.
The error code CLIPBRD_E_CANT_OPEN means that someone else had the clipboard open.

I tried to call GetOpenClipboardWindow in the catch block to identify the conflicting app,
but it returns a null handle. Either the clipboard is again closed at this time,
or the conflict app didn't specify a window object when opening the clipboard.

I couldn't identify the conflicting app. It may be Windows Clipboard History or something else.
I suspected PowerToys AdvancedPaste, but it didn't seem to monitor copying to the clipboard.

Copying to clipboard in PowerToys

I walked through other tools and plugins in PowerToys and checked how they work with clipboard.

These use the same Clipboard.SetText method and exhibit the same issue as far as I can tell:

  • TextExtractor
  • Run/Unit Converter
  • Run/Value Generator
  • Run/Folder
  • Run/Indexer

ColorPicker is using Clipboard.SetDataObject in a non-persistent mode
(evading the internal Flush method call), which means that the copied data won't be available
after the app exists. However, the copied values seem persistent anyway for some reason.
Also, it has a loop and tries to copy up to 10 times if it fails.

The ColorPicker's way works on my machine.

The last group calls Clipboard.Clear first and then Clipboard.SetText.

  • Run/Registry
  • Run/System
  • Run/TimeDate
  • Run/WindowsSettings

I don't know why, but this sequence works. Therefore, I suggest using this until we know more.

@GhostVaibhav
Copy link
Contributor

GhostVaibhav commented Aug 12, 2024

Hi @josefblaha, did you test all the apps in the same environment?

@josefblaha
Copy link

Hi @josefblaha, did you test all the apps in the same environment?

Not all apps, but I tested all the ways of copying. I tried copying in ColorPicker, and in Unit Converter, Folder and TimeDate plugins. Those using just Clipboard.SetText didn't work.

@GhostVaibhav
Copy link
Contributor

GhostVaibhav commented Aug 13, 2024

I see @josefblaha. This issue is only reported for the Calculator plugin but applies to all the utilities using just Clipboard.SetText while copying.

@htcfreek is it better to add the temporary fix to these utilities (since this seems like a high-priority bug) or should we wait for the core team's decision on this?

Also, this seems like the right time to say, but @josefblaha, could you post a video or an image reproducing the error and then another video with the clear statement above so we can have a look if it is indeed working?

@samatWL
Copy link

samatWL commented Nov 14, 2024

not sure if this helps. i found this thread while trying to figure out why it was spontaneously mad at me.
https://stackoverflow.com/questions/68666/clipbrd-e-cant-open-error-when-setting-the-clipboard-from-net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. Product-PowerToys Run Improved app launch PT Run (Win+R) Window Run-Plugin Things that relate with PowerToys Run's plugin interface
Projects
Status: No status
Development

No branches or pull requests