Esatto.Win32.Com 3.0.9

dotnet add package Esatto.Win32.Com --version 3.0.9
NuGet\Install-Package Esatto.Win32.Com -Version 3.0.9
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.9" />
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.9
#r "nuget: Esatto.Win32.Com, 3.0.9"
#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.9

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

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-windows7.0 is compatible.  net8.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.2

    • No dependencies.
  • net7.0-windows7.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.9 215 11/18/2023
3.0.7 86 11/15/2023
3.0.6 98 11/12/2023
3.0.4 92 11/7/2023
3.0.3 98 11/4/2023
3.0.2 98 10/31/2023
3.0.1 135 7/4/2023
3.0.0 150 4/29/2023
1.0.1 133 4/20/2023
1.0.0 134 4/20/2023