Esatto.Win32.Com 3.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Esatto.Win32.Com --version 3.0.1                
NuGet\Install-Package Esatto.Win32.Com -Version 3.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Esatto.Win32.Com" Version="3.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Esatto.Win32.Com --version 3.0.1                
#r "nuget: Esatto.Win32.Com, 3.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Esatto.Win32.Com as a Cake Addin
#addin nuget:?package=Esatto.Win32.Com&version=3.0.1

// Install Esatto.Win32.Com as a Cake Tool
#tool nuget:?package=Esatto.Win32.Com&version=3.0.1                

Esatto Win32 COM

Example out-of-process server

[ComVisible(true)]
public interface IShellApplication
{
    void Navigate(string destination);
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId(SessionApplication.ShellApplicationProgId)]
public sealed class ShellApplication : StandardOleMarshalObject, IShellApplication, IDisposable
{
    private readonly INavigationManager NavMgr;
    private readonly ClassObjectRegistration ThisReg;

    public ShellApplication(INavigationManager navMgr)
    {
        this.NavMgr = navMgr;
        this.ThisReg = new ClassObjectRegistration(typeof(ShellApplication).GUID,
            ComInterop.CreateClassFactoryFor(() => this), CLSCTX.LOCAL_SERVER, REGCLS.MULTIPLEUSE | REGCLS.SUSPENDED);
        ComInterop.CoResumeClassObjects();
    }

    public void Dispose()
    {
        this.ThisReg.Dispose();
    }

    public void Navigate(string destination) 
    {
        NavMgr.Navigate(destination);
    }

    #region Registration

    [Obsolete("Implemented only to support regasm, use .ctor(INavigationManager)")]
    public ShellApplication()
    {
        // required for regasm
        throw new InvalidOperationException();
    }

    [ComRegisterFunction]
    internal static void RegasmRegisterLocalServer(string path)
    {
        // path is HKEY_CLASSES_ROOT\\CLSID\\{clsid}", we only want CLSID...
        path = path.Substring("HKEY_CLASSES_ROOT\\".Length);
        using (var keyCLSID = Registry.ClassesRoot.OpenSubKey(path, writable: true)!)
        {
            // Remove the auto-generated InprocServer32 key after registration
            // (REGASM puts it there but we are going out-of-proc).
            keyCLSID.DeleteSubKeyTree("InprocServer32");
            using (var ls32 = keyCLSID.CreateSubKey("LocalServer32"))
            {
                ls32.SetValue(null, Assembly.GetExecutingAssembly().Location);
            }
        }
    }

    [ComUnregisterFunction]
    internal static void RegasmUnregisterLocalServer(string path)
    {
        // path is HKEY_CLASSES_ROOT\\CLSID\\{clsid}", we only want CLSID...
        path = path.Substring("HKEY_CLASSES_ROOT\\".Length);
        Registry.ClassesRoot.DeleteSubKeyTree(path, throwOnMissingSubKey: false);
    }

    #endregion Registration
}

Register with regasm or DSCOM

Example out-of-process client

SessionApplication.Navigate("Example");

public static class SessionApplication
{
    public const string ShellApplicationProgId = "Example.Shell.Application.1";

    public static IShellApplication GetOrOpenShell()
    {
        var app = (IShellApplication)ComInterop.CreateLocalServer(ShellApplicationProgId);
        try
        {
            ComInterop.CoAllowSetForegroundWindow(app);
        }
        catch
        {
            // Nop, we may not have foreground
        }
        return app;
    }
}

Run with impersonation

ComInterop.RunImpersonated(() =>
{
    var ident = WindowsIdentity.GetCurrent(true);
    Console.WriteLine(ident.User);
});
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Esatto.Win32.Com:

Package Downloads
Esatto.Win32.CommonControls

Tools for manipulating HWNDs, watching other windows, and utilizing shell registrations

Esatto.AppCoordination.Common

Package Description

Esatto.Win32.RdpDvc.Common

Core API's for working with Remote Desktop Protocol Dynamic Virtual Channels

Itp.WpfCrossProcess.Common

Controls for running WPF controls in a different process, composed visually in a main app.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.17 124 7/14/2024
3.0.9 268 11/18/2023
3.0.7 114 11/15/2023
3.0.6 120 11/12/2023
3.0.4 114 11/7/2023
3.0.3 124 11/4/2023
3.0.2 124 10/31/2023
3.0.1 181 7/4/2023
3.0.0 174 4/29/2023
1.0.1 158 4/20/2023
1.0.0 159 4/20/2023