FindMyFiles
FindMyFiles.Services
ServiceSetup Class
In-app service setup — the GUI half ADR-0016 left to a terminal: detects the fmf-engine SCM registration (read-only, works unelevated) and drives fmf-service.exe install/start so the one-time elevation never needs PowerShell. Mutations are strictly user-initiated (the notification button); install is idempotent on the service side.
public static class ServiceSetup
Inheritance System.Object → ServiceSetup
Methods
ServiceSetup.CurrentUserSid() Method
The current user's SID string, forwarded to `fmf-service install --owner-sid` so OTS elevation (a *different* admin account) does not lock this user out of the pipe (threat 1). Null when unavailable — install then authorizes only the elevated account.
public static string? CurrentUserSid();
Returns
System.String
The current user's SID string, or null when it cannot be read.
ServiceSetup.IsProcessElevated() Method
True when *this* process is already running with an Administrator token — the in-proc engine path needs it, and when set the in-app install/start verbs can skip their own UAC prompt.
public static bool IsProcessElevated();
Returns
System.Boolean
True when the current process token is in the Administrators role.
ServiceSetup.IsValidSid(string) Method
A well-formed SID string (S-1-… of digits and hyphens) — guards the value going onto the fmf-service command line against argument injection before it is interpolated.
public static bool IsValidSid(string? s);
Parameters
Candidate SID string to validate.
Returns
System.Boolean
True when the value is a well-formed SID safe to pass on the command line.
ServiceSetup.LocateServiceExe(string) Method
fmf-service.exe next to the app (the dist bundle) or in the dev tree (build\engine\release, walking up from the bin dir).
public static string? LocateServiceExe(string baseDir);
Parameters
baseDir System.String
Directory to start the search from (typically the app's bin dir).
Returns
System.String
Full path to fmf-service.exe, or null when it cannot be found.
ServiceSetup.QueryServiceProcessId() Method
PID of the running fmf-engine service process, or 0 when it is not installed/running. The client-side fake-server check (threat 4) compares this to the pipe's server PID — an unelevated client can read it (unlike a SYSTEM process's token), and a squatter never matches because registering the service needs admin.
public static uint QueryServiceProcessId();
Returns
System.UInt32
The running service's process id, or 0 when not installed/running.
ServiceSetup.QueryState() Method
Read-only SCM query for FindMyFiles.Engine.EngineContract.ServiceName.
public static FindMyFiles.Services.EngineServiceState QueryState();
Returns
EngineServiceState
The service's install/run state for the offer logic.
ServiceSetup.RunElevated(string, string) Method
Run one fmf-service lifecycle verb elevated via a per-action UAC prompt (Verb=runas) — the in-app service manager, where the app itself stays asInvoker. Output can't be captured under ShellExecute, so the verdict is the exit code; a declined prompt (ERROR_CANCELLED 1223) is reported distinctly. args is built from fixed verbs plus SID-validated flags, never raw user text. Blocking — call off the UI thread.
public static FindMyFiles.Services.ServiceActionResult RunElevated(string exe, string args);
Parameters
exe System.String
Path to fmf-service.exe to launch elevated.
args System.String
Service verb plus SID-validated flags to pass on the command line.
Returns
ServiceActionResult
The classified outcome and raw exit code of the elevated action.