Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 962
daibatzu Avatar asked Apr 20 '19 23:04

daibatzu


People also ask

How do I bring up the Windows dialog box?

1. Use a Keyboard Shortcut. The fastest way to access most Windows software programs is through keyboard shortcuts. To quickly access the Run command dialog box, simply press the Windows key + R.

How do I open the Run dialog box in Windows 10?

The quickest way to access the Run command window is to use this keyboard shortcut: Windows + R. Simply hold down the Windows key and press R on your keyboard. On top of being very easy to remember, this method works in all versions of Windows, from the dated Windows 7 to the newer Windows 10 and the latest Windows 11.

How do I open my computer with command prompt?

The easiest way is to type shell:mycomputerfolder or Win+E Note that running command shell:mycomputerfolder will not start mycomputerfolder if it's already open. On the other hand pressing win+e will open mycomputerfolder as many times as you press it. Works for me on Windows 10 1809.

How do you open a dialog box on a computer?

CTRL + F12 help to open dialogue box.


1 Answers

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

like image 60
daibatzu Avatar answered Oct 21 '22 13:10

daibatzu