Folder Service Sample

This is a console application in which a Shell folder demonstrates a Windows service written using ShellBoost. This sample is simple and quite similar to the Overview sample. However, it runs as a Windows service, in its own security context, instead of running in an end-user desktop context. The sample demonstrates ShellBoost's impersonation capabilities.

The code is the standard .NET code that was created using this article from MSDN: Walkthrough: Creating a Windows Service Application in the ComponentDesigner. The code was changed, however, to retarget the process to be a console application instead of Windows. This has allowed us to add some test code in the program's Main() method.

To run the service, don't forget to install it first. The project contains an "install.bat" file that you can run, under administrative privileges. Once installed, you may use the Windows Service Manager to start or stop it:


If you navigate to the "Samples.FolderService" folder, you should see something like this:


Following is the relevant code in RootFolder.cs:

public override IEnumerable<ShellItem>
EnumItems(SHCONTF options)
{
    yield return new SimpleItem(this, "Client
Principal Name: " + ShellContext.Current.ClientPrincipalName);
    yield return new SimpleItem(this, "Client
Process Id: " + ShellContext.Current.ClientProcessId);
    yield return new SimpleItem(this, "Client
Process: " +
Process.GetProcessById(ShellContext.Current.ClientProcessId)?.ProcessName);
 
    // if we impersonate, this will be the same as the
client principal name
    // otherwise it will be the identity that runs the
service process
    yield return new SimpleItem(this, "Server
Windows Identity: " + WindowsIdentity.GetCurrent()?.Name);
    yield return new SimpleItem(this, "Server
Process: " + Process.GetCurrentProcess().ProcessName);
}

Please see the Security Considerations chapter for more details on this sample.

Copyright (c) 2022 Callback Technologies, Inc. - All rights reserved.
CBFS Shell 2022 .NET Edition - Version 22.0 [Build 8367]