在Windows 10中,如果您右键单击图像,您将发现一个名为“共享”的选项。
点击它会打开一个对话框,在这里您可以通过电子邮件、OneNote等方式分享图片。
有没有人知道我怎么可以从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
$explorer = new-object -comobject shell.application
用于控制外壳程序,然后$Explorer.NameSpace ("D:\folder\").ParseName("TestImage.jpg").Verbs()
将显示它,动作名称为“Share”,但尝试调用DoIt()
来调用它会导致异常:Exception calling "DoIt" with "0" argument(s): "Invalid window handle. (Exception from HRESULT: 0x80070578)"
。注意,“如何调用此对话框?”这个问题并不等同于“如何将共享添加到我的 UWP 应用程序?”。 - TessellatingHeckler