Skip to content

Instantly share code, notes, and snippets.

@vmassuchetto
Last active June 8, 2023 04:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmassuchetto/53d5d787b2601cd8670a772d0de8ae41 to your computer and use it in GitHub Desktop.
Save vmassuchetto/53d5d787b2601cd8670a772d0de8ae41 to your computer and use it in GitHub Desktop.
Shell script to open files in a VirtualBox Windows guest from the Linux host
#!/bin/bash
# Based on http://tinyurl.com/jmze5lw with some additions
# Dependencies: detox wmctrl
# In your VM, share the root host location "/" in $DRIVE
SCRIPTPATH="$(basename "$0")"
VMNAME="WindowsXP"
DRIVE="E:"
# Start vm if not running already
if [ $(VBoxManage list runningvms | wc -l) = 0 ]; then
VBoxManage startvm $VMNAME
sleep 5s
fi
# Wait until graphics are available
until VBoxManage showvminfo $VMNAME | grep '"Graphics Mode": active/running' > /dev/null
do
sleep 0.5s
done
for FILE in "$@"
do
# Set a converted file path
if echo $FILE | grep '^/' > /dev/null; then
TARGETPATH=$FILE
else
TARGETPATH=$PWD'/'$FILE
fi
CLEANPATH=$(detox -vs utf_8 "$TARGETPATH" | tail -1 | awk '{print $NF}')
WINPATH=$(echo $DRIVE$CLEANPATH | sed 's/\//\\/g')
# Start application in VirtualBox
VBoxManage guestcontrol "$VMNAME" run --exe "cmd.exe" --username "Vinicius Massuchetto" -- "cmd" "/c" $WINPATH &
# Change window manager focus to VM
wmctrl -a "$VMNAME"
done
@HenzelMoras
Copy link

VBoxManage guestcontrol $vm_name run --exe "${guest_path}tool-script/install-tools.sh" --username $guest_user --password $guest_passwd --wait-stdout --wait-stderr

i get error:
Running install-tools.sh
VBoxManage: error: Waiting for guest process (flags 0x1) failed: Error "Access denied." (VERR_ACCESS_DENIED) for guest process "/home/user/Desktop/tool-script/install-tools.sh" occurred

VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component GuestProcessWrap, interface IGuestProcess, callee nsISupports
VBoxManage: error: Context: "WaitForArray(ComSafeArrayAsInParam(aWaitStartFlags), gctlRunGetRemainingTime(msStart, cMsTimeout), &waitResult)" at line 1496 of file VBoxManageGuestCtrl.cpp

i checked the script needs execute permissions in guest

How can i make the script executable within guest from host ?

PS : thanks in advance

@Konfekt
Copy link

Konfekt commented Mar 24, 2023

This older blog post gives a similar script and discusses how to integrate it into the XDG Desktop Linux environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment