简体   繁体   中英

View file containing Windows Clipboard content in Command Prompt

I want to do a very simple task, and yet somehow the hundreds of questions on SO surrounding the topic always manage to skirt answering this exact one (from what I can find).

The task is this: I want to view the source file that holds the Clipboard contents.

I know that older Windows OS had an option for Clipboard Viewers, and for newer OS you can use third-party viewers, but I want to view the actual source file itself. It has to be stored in some file somewhere, doesn't it? This answer gets close by at least letting me view the text natively without 3rd party software, but I still can't figure out where it's pulling its information from. I don't want the user-friendly version, I want to see whatever the computer is using (HTML, XML, UNICODE, C, or even binary, I have no idea).

There has to be some way to view the contents of that file in Command Prompt (or PowerShell), doesn't there? Why is this information so hard to find?

The short answer is through invoking the static method from the System.Windows.Form.Clipboard class in the .NET framework.

[System.Windows.Forms.Clipboard]::GetText()

This will work in powershell as-is, and will return to you whatever is currently stored in your clipboard.

Now, without going beyond the scope of our main topic being powershell/CLI, you can peruse through the class in User32.lib or User32.dll.

See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms649014(v=vs.85).aspx

My original short answer should be sufficient for what I think you're looking to do, which is return the content of whatever is in clipboard back out to your powershell/cli host in plaintext.

This information was easily found by googling

powershell get clipboard contents

Also, if you want a more in-depth walkthrough: http://powershell-tips.blogspot.com/2011/05/handling-clipboard-with-powershell.html

Windows is not a GNU/Linux OS. AFAIK there isn't really a clipboard daemon that stores content in a plaintext file somewhere on the filesystem. With .NET being natively available in powershell, you can just invoke these classes directly to get what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM