daibatzu
daibatzu

Reputation: 517

How to call up windows 10 share dialog box from powershell or cmd

In windows 10, if you right click on an image, you will find an option called "Share".

Clicking this opens up a dialog box where you can share the image via email, one note e.t.c.

Does anyone know how I can call this up from CMD or PowerShell? as I would like to add this feature to my app.

I have gotten to this point but get an invalid window handle error:

$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)
}

Also, using RUNDLL doesn't work either:

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

Upvotes: 13

Views: 1206

Answers (1)

daibatzu
daibatzu

Reputation: 517

Thanks to @Simon Mourier for pointing me to the answer. The solution can be found on https://github.com/daibatzu/electron-sharing

Using visual studio you can build an exe file, I have included instructions in the readme.txt

The generated exe is WindowsFormsApp2.exe You can then share files by using:

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

You can test this by opening a cmd prompt, navigating to the folder containing WindowsFormsApp2.exe and passing filenames as parameters.

Clicking outside the share dialog will close WindowsFormsApp2.exe You will need to use visual studio to change the icon for this app unfortunately

I have included a release just in case you do not know visual studio or C#. You will need 7-zip (free download) to unzip it.

Once again, thanks to Simon. This took way longer than I imagined.

EDIT

problems with github so zip file is here: https://drive.google.com/file/d/1jyBqO6jmGo5dSxw32LXa5lej1J3ElD34/view?usp=sharing

Upvotes: 2

Related Questions