Skip to content

usbipd policy state command similar to usbipd state #1349

@nickbeth

Description

@nickbeth

Hey, I'm the author of the WSL USB Manager GUI for this tool.

I'm currently trying to implement more advanced auto attach functionalities in my app (currently only uses auto-attach command, but auto-attach profiles are forgotten on app relaunch), and I found that it would map pretty cleanly by implementing a "port auto-bind" feature by leveraging the new policy system.
My idea is to create a new policy for a port, store the GUID as the ID of that "auto-attach profile", and then use that GUID to remove it if the user doesn't want auto attach on that port anymore.

Here's the issue: I'm using ShellExecuteEx to launch an elevated usbipd process to run commands, but there isn't a straightforward way to capture stdout (where the GUID is printed). One would need to use CreateProcess, but that doesn't support running elevated AFAIK. Therefore, I'm stuck at doing all kinds of weird hacks just to capture the stdout of the policy add command via a child process, which passes it through some named pipe/mailslot so that it reaches back to the main process.
This is nasty and I'd like to avoid it. I'd also like to avoid needing to run my entire app as administrator, both because there's no need for that, and also for my own peace of mind (don't want any lingering bugs breaking people's PCs).

So my only option here would be to ignore the GUID printed to stdout (which honestly is fine, I already rely on state for other commands) and parse the policy list output, but:

  1. It's not the most parsable format as it's made for human readibility
  2. I don't think it's a stable format as it could change in the future (?)

TL;DR: Is there any chance we could get a parsable (JSON) formatted output for policies with a command like usbipd policy state, just like the usbipd state command?

P.S. If you believe there's an alternative solution to the issue I described that I'm not seeing, please let me know!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions