【问题标题】:Powershell - Windows.Clipboard not foundPowershell - 找不到Windows.Clipboard
【发布时间】:2016-04-13 04:32:11
【问题描述】:

我在使用 Powershell 和 cmd 时遇到问题。我有一个引用剪贴板的脚本

[System.Windows.Clipboard]::SetText("My text");

我在 Powershell 编辑器中运行脚本,一切正常。当我尝试从命令行运行它时

powershell.exe -c myscript.ps1

我收到此错误:找不到类型 [System.Windows.Clipboard]

(我是从法语翻译过来的,我想这相当于英文)

有什么想法吗?

【问题讨论】:

  • 首先运行这个Add-Type -Assembly PresentationCore
  • 这解决了我的问题!谢谢@AnthonyStringer :)

标签: windows powershell cmd clipboard


【解决方案1】:

就像@AnthonyStringer 所说,我必须先使用命令导入 PresentationCore

Add-Type -Assembly PresentationCore

这样,当从 cmd 调用 powershell 时,它能够调用 Windows.Clipboard。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 2020-04-02
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多