{"record":{"id":"7f6452745af718c8","repo":"dotnet/wpf","slug":"printsystemexception-printserver-commit","errorCode":null,"errorMessage":"PrintSystemException.PrintServer.Commit","messagePattern":"PrintSystemException\\.PrintServer\\.Commit","errorType":"exception","errorClass":"PrintServerException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp","lineNumber":1065,"sourceCode":"    void\n\n--*/\nvoid\nLocalPrintServer::\nCommit(\n    void\n    )\n{\n    VerifyAccess();\n\n    try\n    {\n        ComitDirtyData(GetAlteredPropertiesFilter());\n        PrintServer::Commit();\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        throw CreatePrintServerException(internalException->HResult, \"PrintSystemException.PrintServer.Commit\");\n    }\n}\n\n/*++\n\nRoutine Name:\n\n    Refresh\n\nRoutine Description:\n\n    Refreshes the object attributes.\n\nArguments:\n\n    None\n\nReturn Value:","sourceCodeStart":1047,"sourceCodeEnd":1083,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp#L1047-L1083","documentation":"Thrown by LocalPrintServer.Commit when writing dirty server properties back to the spooler fails. LocalPrintServer first commits its own dirty data (ComitDirtyData) then calls PrintServer::Commit; any InternalPrintSystemException from those Win32 operations is converted to this PrintSystemException.","triggerScenarios":"Calling LocalPrintServer.Commit() after changing properties (e.g. DefaultPrintQueue, scheduler priority, spool folder) when the Win32 SetPrinter/registry writes fail due to lack of administrator rights or an invalid value.","commonSituations":"Non-admin processes trying to change machine-wide print server settings; UAC elevation missing; invalid configuration values (e.g. bad spool folder path) written to the print server registry keys.","solutions":["Run with administrator privileges when committing server-level (machine-wide) print settings.","Validate changed property values before Commit (paths exist, enums valid).","Catch the exception and inspect the inner HResult to find which property failed.","Commit only properties you actually changed; avoid wholesale Refresh/Commit cycles on read-only servers."],"exampleFix":"// before\nserver.DefaultPrintQueue = queue;\nserver.Commit(); // requires admin for server settings\n// after\nif (IsElevated())\n{\n    server.DefaultPrintQueue = queue;\n    server.Commit();\n}","handlingStrategy":"try-catch","validationCode":"static bool IsElevated()\n{\n    using var identity = System.Security.Principal.WindowsIdentity.GetCurrent();\n    var principal = new System.Security.Principal.WindowsPrincipal(identity);\n    return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);\n}","typeGuard":"static bool CanCommitServerSettings() => IsElevated();","tryCatchPattern":"try { server.Commit(); }\ncatch (PrintSystemException ex)\n{\n    throw new UnauthorizedAccessException(\n        \"Committing print server settings requires administrator privileges\", ex);\n}","preventionTips":["Elevate the process (runas/UAC) before committing machine-wide print settings","Only modify and commit properties you actually intend to change","Validate modified values (paths, enums) before calling Commit"],"tags":["printing","permissions","commit","wpf"],"backgroundTag":"permission-denied","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}