2

I use QEMU to run a Windows 10 virtual machine (VM) on an Ubuntu host. My goal is to programmatically instruct the VM to run a specific GUI program in the foreground, as if the user had started the program.

The Windows guest already has the guest agent installed. On the host I can execute

virsh qemu-agent-command win10_vm "{\"execute\": \"guest-exec\", \"arguments\": { \"path\": \"notepad.exe\", \"arg\": [], \"capture-output\": true}}"

and I can see from the task manager that notepad.exe is executed in the background. However, I would have liked the GUI to open.

What I tried so far without success:

  • On the Windows guest, run the guest agent service as the user.
  • For the qemu-agent-command, change path to execute from notepad.exe to start notepad.exe, but then the command failed with an error.

Does anyone know how to instruct the VM to run a program in the foreground?

1 Answer 1

2

(sorry for the repost, I posted previously and got it completely wrong, my mistake)

The reason for this is because by default, the Qemu-GA service runs as the SYSTEM user on session 0, since Windows XP, session 0 is isolated from the UI session for security reasons

You can bypass this by using psexec to switch to the user's interactive service.

For step by step instructions, follow:

  1. Open services.msc, find the Qemu-GA, and on its Log-on tab, select to run as a specific user, and enable desktop access. Stop, and then start the service.
  2. Download and extract psexec to C:\psexec.exe (or any other path of your choosing)
  3. You can now use the following command to launch UI as the user.

qm guest exec 100 -- C:\\psexec.exe -accepteula -i 1 notepad.exe (for proxmox)

virsh -c qemu:///system qemu-agent-command win10_vm "{\"execute\": \"guest-exec\", \"arguments\": { \"path\": \"C:\\\\Users\\\\matt\\\\Downloads\\\\PSTools\\\\PsExec.exe\", \"arg\": [\"-accepteula\", \"-i\", \"1\", \"notepad.exe\"], \"capture-output\": true}}" (for libvirt)

1
  • 1
    Thanks! Your instructions put me on track. I needed two more modifications: 1) psexec failed with an access error until I disabled the firewall on the guest (not ideal, but the VM runs for a few minutes only). 2) Had to modify the command to virsh -c qemu:///system qemu-agent-command win10_vm "{\"execute\": \"guest-exec\", \"arguments\": { \"path\": \"C:\\\\Users\\\\matt\\\\Downloads\\\\PSTools\\\\PsExec.exe\", \"arg\": [\"-accepteula\", \"-i\", \"1\", \"notepad.exe\"], \"capture-output\": true}}" Commented Apr 8, 2023 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .