windows - 如何从powershell或cmd调出windows 10共享对话框

标签 windows powershell cmd

在 Windows 10 中,如果您右键单击图像,您会发现一个名为“共享”的选项。

单击此按钮会打开一个对话框,您可以在其中通过电子邮件、一张便条等分享图像。

有谁知道如何从 CMD 或 PowerShell 调用它?因为我想将此功能添加到我的应用程序中。

我已经到了这个地步但是得到了一个无效的窗口句柄错误:

$Target = "C:\Users\igweo\OneDrive\Pictures\wallpapers\luca-zanon-26595-unsplash.jpg"

$KeyPath1  = "HKCU:\SOFTWARE\Classes"
$KeyPath2  = "*"
$KeyPath3  = "shell"
$KeyPath4  = "{:}"
$ValueName = "ExplorerCommandHandler"
$ValueData = (Get-ItemProperty("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\" +
  "Explorer\CommandStore\shell\Windows.ModernShare")).ExplorerCommandHandler


$Key2 = (Get-Item $KeyPath1).OpenSubKey($KeyPath2, $true)
$Key3 = $Key2.CreateSubKey($KeyPath3, $true)
$Key4 = $Key3.CreateSubKey($KeyPath4, $true)
$Key4.SetValue($ValueName, $ValueData)

$Shell = New-Object -ComObject "Shell.Application"
$Folder = $Shell.Namespace((Get-Item $Target).DirectoryName)
$Item = $Folder.ParseName((Get-Item $Target).Name)
$Item.InvokeVerb("{:}")

$Key3.DeleteSubKey($KeyPath4)
if ($Key3.SubKeyCount -eq 0 -and $Key3.ValueCount -eq 0) {
    $Key2.DeleteSubKey($KeyPath3)
}

此外,使用 RUNDLL 也不起作用:

RUNDLL32.EXE NTSHRUI.DLL,ShowShareFolderUI C:\Users\igweo\OneDrive\Pictures\wallpapers\luca-zanon-26595-unsplash.jpg

最佳答案

感谢@Simon Mourier 指出我的答案。 解决方案可以在 https://github.com/daibatzu/electron-sharing 上找到

使用 visual studio 你可以构建一个 exe 文件,我在 readme.txt 中包含了说明

生成的exe是WindowsFormsApp2.exe 然后,您可以使用以下方式共享文件:

WindowsFormsApp2.exe "C:\Projects\Javascript\photos\celeste.png""C:\Projects\Javascript\photos\Silvercoins.jpg"

您可以通过打开 cmd 提示符、导航到包含 WindowsFormsApp2.exe 的文件夹并将文件名作为参数传递来对此进行测试。

在共享对话框外单击将关闭 WindowsFormsApp2.exe 不幸的是,您将需要使用 visual studio 来更改此应用程序的图标

我已经包含了一个版本,以防您不了解 visual studio 或 C#。您将需要 7-zip(免费下载)来解压它。

再次感谢 Simon。 这比我想象的要长得多。

编辑

github 的问题所以 zip 文件在这里:https://drive.google.com/file/d/1jyBqO6jmGo5dSxw32LXa5lej1J3ElD34/view?usp=sharing

关于windows - 如何从powershell或cmd调出windows 10共享对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55778570/

相关文章:

windows - 如何在D应用程序中添加图标?

java - PowerShell 中手动执行和编程执行的输出不同

.net - Powershell Get-Date -Day(新年)

django - 错误信息 'mkvirtualenv is not recognized as an internal or external command'

sorting - grep 并使用模式文件进行排序

cmd - 在 Windows 文件关联操作命令行中使用 &&

windows - 如何在 Apache 和 Win7 下使用 node.js 在端口 80 上创建服务器?

C# 发送键盘输入

powershell - 如何从命令行 Windows 7 设置代理

windows - 30000 毫秒后 Protractor 超时