{"record":{"id":"867e307f6efd6c2b","repo":"babalae/better-genshin-impact","slug":"exe","errorCode":null,"errorMessage":"当前只允许选择 .exe 程序。","messagePattern":"当前只允许选择 \\.exe 程序。","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Service/ChildSession/ChildSessionProcessLauncher.cs","lineNumber":208,"sourceCode":"            ReleaseComObject(registeredTaskObject);\n            ReleaseComObject(actionObject);\n            ReleaseComObject(taskDefinitionObject);\n            ReleaseComObject(rootFolderObject);\n            ReleaseComObject(schedulerObject);\n        }\n    }\n\n    private static string ValidateExecutablePath(string executablePath)\n    {\n        var fullPath = Path.GetFullPath(executablePath);\n        if (!File.Exists(fullPath))\n        {\n            throw new FileNotFoundException(\"要启动的程序不存在。\", fullPath);\n        }\n\n        if (!string.Equals(Path.GetExtension(fullPath), \".exe\", StringComparison.OrdinalIgnoreCase))\n        {\n            throw new ArgumentException(\"当前只允许选择 .exe 程序。\", nameof(executablePath));\n        }\n\n        return fullPath;\n    }\n\n    private static string QuoteArgument(string argument)\n    {\n        return $\"\\\"{argument.Replace(\"\\\"\", \"\\\\\\\"\", StringComparison.Ordinal)}\\\"\";\n    }\n\n    private static void ReleaseComObject(object? value)\n    {\n        if (value is not null && Marshal.IsComObject(value))\n        {\n            Marshal.FinalReleaseComObject(value);\n        }\n    }\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/ChildSession/ChildSessionProcessLauncher.cs#L190-L226","documentation":"Thrown by ValidateExecutablePath when the selected file's extension is not \".exe\" (case-insensitive). The Task Scheduler exec action used for elevated Child Session launch requires a real executable; scripts and shortcuts are rejected to avoid ambiguous behavior.","triggerScenarios":"User selects a .bat, .cmd, .ps1, .lnk, .msi, or a file with no extension via LaunchExecutableAsync.","commonSituations":"User tries to launch a batch file or PowerShell script directly into the Child Session; user picks a Start Menu shortcut (.lnk).","solutions":["Select a .exe file directly.","To run a script, launch cmd.exe or powershell.exe as the executable and pass the script path as an argument.","Convert the script into a packaged executable if frequent launches are needed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var fullPath = Path.GetFullPath(executablePath);\nif (!string.Equals(Path.GetExtension(fullPath), \".exe\", StringComparison.OrdinalIgnoreCase))\n{\n    throw new ArgumentException(\"当前只允许选择 .exe 程序。\", nameof(executablePath));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await launcher.LaunchElevatedAsync(childSessionId, exePath);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\".exe\"))\n{\n    logger.LogWarning(\"Only .exe files are allowed for Child Session launch\");\n}","preventionTips":["Filter the file picker to *.exe so users cannot select other extensions.","Document that scripts must be wrapped (cmd.exe/powershell.exe as the executable) in the launch UI.","Validate the extension before dispatching to the Task Scheduler path."],"tags":["validation","path","configuration","child-session"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}