Last active
March 6, 2025 13:35
-
-
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...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HWND | |
IShellItemArray | |
ILCreateFromPath | |
ILFree | |
SharingConfigurationManager | |
SHCreateShellItemArrayFromIDLists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment