2

How can I associate file types in desktop Linux with Windows 7 applications running through VirtualBox so they work seamlessly, starting VirtualBox if required?

I'm using KDE.


Current method

(example for Excel files):

Add a new entry in the start menu called "Excel"

  • Command: /home/USER/bin/excelstarter.sh %f
    • See below
  • Launch feedback does not work well so it's disabled

Associate .xlsx files with "Excel" by right clicking and choosing run as...

  • Remember application associations for all files of type ...

Mount relevant folders in VirtualBox

  • VirtualBox main window > Settings for machine > Shared folders:

    • Add:
      • Folder path: /data
      • Auto mount
      • Make permanent
    • Add:
      • Folder path: /home/USER
      • Auto mount
      • Make permanent

Disable group policy restriction on empty passwords

Without this change VirtualBox will not run commands if no password has been set.

  • Run gpedit.msc
  • Navigate to

    Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options

  • Change

    Limit local account use of blank passwords to console logon only to Disabled.


excelstarter.sh

The idea here is that this file takes care of starting VirtualBox if it is not already running, waiting for it to start up and then starts Excel with a filepath that has been translated to the corresponding mounts set up in VirtualBox.

# Start VM (if it is already started this does nothing)
VBoxManage startvm "win7_hilti"

# Replace folders with windows-local versions (mounts need to be setup)
# /data/ is mounted as F:
original=$1
findWhat=\/data/
replaceWith="F:\\"
fixedFilePath="${original/$findWhat/$replaceWith}"

# /home/USER/ is mounted as G:
original=$fixedFilePath
findWhat=\/home\/USER/
replaceWith="G:\\"
fixedFilePath="${original/$findWhat/$replaceWith}"

# Used for debugging the file paths
#notify-send $fixedFilePath

# Start Excel
# Try to run it until it the machine has started
until VBoxManage guestcontrol "VM-NAME" start --exe "C:\\Program Files\\Microsoft Office\\Office14\\EXCEL.EXE" --username WINDOWSUSER "excel" -- "$fixedFilePath"
do
  # Sleep 1 gave the problem that the mounts were not yet ready, sleep 2 seems to work fine
  sleep 2
done

Problems

  • VirtualBox does not get focus if it was already running in the background.
  • Ugly sleep in the loop while waiting for VirtualBox to start. Sleep 1 gave problems where the mounts were not yet set up. On a slower machine this value might need to be increased.
  • Sometimes it does not start Excel after VirtualBox has started.

References

VBoxManage guestcontrol

The fix to enable passwordless use

2

Several tweaks:

-- instead of hardcoding the path to application, I used cmd.exe start command:

options=( --username WINDOWSUSER --exe "%SystemRoot%\system32\cmd.exe" -- 'cmd' /c start "run this" "$fixedFilePath" ) where $fixedFilePath is as in your code. These options work even if $fixedFilePath contains blanks.

This generalises the script -- it will work now for any type of file, not just excel files.

It should also work if $fixedFilePath is a full path to a programme within your windows guest; the name (with extension) of a programme on %PATH; or the name (with extension) if a registered programme, e.g. winword.exe, excel.exe.

I then tested the string returned by VBoxManage guestcontrol on stderr:

nError=1
nTries=0

while [ $nError -gt 0 ] && [ $nTries -lt 20 ]; do

   nError=$(VBoxManage guestcontrol win7_hilti start "${options[@]}" 2>&1 >/dev/null | grep -c "error")
   ((++nTries))
   sleep 2

done

(some of which I borrowed from this source)

5
  • I do not understand "run this" in the line /// -- 'cmd' /c start "run this" "$fixedFilePath" /// from above. I have not found this command in WindowsDos-cmd-help-start-command and I also I have not found this command in Linux-VirtualBox-VBoxManage-guestcontrol-command. I have tried your code without "run this", but this was not successful. So where can I find information about "run this". For what is this good for and where is it documented? – Wogehu Dec 27 '20 at 15:01
  • 1
    "start" takes one mandatory parameter, "Text for the CMD window title bar (required.)" link. So any text you like in quotes, including the null string, but it's gotta be there. – EntropyReduction Dec 28 '20 at 16:05
  • Whenever the host starts a program with /// VBoxManage guestcontrol "Win7" start --username XX --password XX --exe "%SystemRoot%\system32\cmd.exe" ///, then in the guest task-manager I have again an additional process "VBoxService.exe". When I put my VM in "save state" and start it again, then this processes are still open. I guess there is no way to close this processes automatically. Maybe within the "starter.sh" ? – Wogehu Jan 11 at 11:40
  • Same with the process "conhost.exe" – Wogehu Jan 11 at 14:00
  • I don't know what VBoxService.exe does exactly, and I certainly don't know what two of them are running for when you launch guest via guestcontrol. So no, no idea how to stop, or even whether it would be desireable to do so. – EntropyReduction Jan 13 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.