Skip to content

Instantly share code, notes, and snippets.

@riverar
Last active March 6, 2025 13:35
Show Gist options
  • Save riverar/4158e24d7cee50d1e789ca12299eecf6 to your computer and use it in GitHub Desktop.
Save riverar/4158e24d7cee50d1e789ca12299eecf6 to your computer and use it in GitHub Desktop.
Sample code to display the Sharing Configuration UI (i.e., Give access to... > Specific people...)
using System.Runtime.InteropServices;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.UI.Shell;
using System.Windows;
using System.Windows.Interop;
namespace WpfApp10
{
//
// WARNING: Tested only on Windows vNext 27802.rs_prerelease.250222-1646
//
[Guid("14aa4ab8-abe3-4a07-a290-1d5dccdd2fc2")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface ISharingConfigurationUI
{
// ntshrui!CSharingConfiguration::CanShareItems(IShellItemArray *)
HRESULT __CanShareItems__Stub();
// ntshrui!CSharingConfiguration::ShowShareItemsUI(HWND *, IShellItemArray *)
HRESULT ShowShareItemsUI(HWND hwnd, IShellItemArray items);
// ntshrui!...
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private unsafe void Window_Loaded(object sender, RoutedEventArgs e)
{
var hwnd = new WindowInteropHelper(this).Handle;
var idlist = PInvoke.ILCreateFromPath(@"C:\Temp");
PInvoke.SHCreateShellItemArrayFromIDLists(1, &idlist, out var array);
var config = (ISharingConfigurationUI)new SharingConfigurationManager();
config.ShowShareItemsUI(new HWND(hwnd), array);
PInvoke.ILFree(idlist);
}
}
}
HWND
IShellItemArray
ILCreateFromPath
ILFree
SharingConfigurationManager
SHCreateShellItemArrayFromIDLists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment