Shared folders using a bat file: how, when and where?

Discussions related to using VirtualBox on Windows hosts.
Post Reply
science2002
Posts: 41
Joined: 4. Jan 2021, 01:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win10, WinXP, Android

Shared folders using a bat file: how, when and where?

Post by science2002 »

Knowing that drag&drop does not always work well, while "shared folders" seem a more reliable way to connect guest with host and external drives, I was thinking a quick way to set this feature, when needed.
With the help manual and some posts from this forum I wrote the following bat file. I would be greateful if someone spots errors or gives suggestions to improve it.
The folder that I would like to share temporarily (i.e. when needed) is from a USB drive (with path "D:\my_external_path").

Code: Select all

echo on
c:
cd "c:\Program files\VirtualBox\"
VBoxManage sharedfolder add "myVM_name" --name "mySharedFolders_name" --hostpath "D:\my_external_path" --transient --automount
pause
echo off
exit
I ask here the following before messing up the VB machines with my attemps.
a) Can the bat file be run before launching the guest VM and it is safer to do so? In my testing in fact I see that the script asks theGuest VM needs to be open.
b) Is there a way to run a similar bat file within the Guest VM (it would be better: each Guest VM has its own bat file), instead from the host OS?
Thanks
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Shared folders using a bat file: how, when and where?

Post by scottgus1 »

I've not made a shared folder with a vboxmanage command. But the command you posted makes sense.

I agree that my experience with Drag-n-drop hasn't been 100% and that Virtualbox or real shared folders are the cat's meow.

It is also possible to start a VM from a batch file: vboxmanage startvm "VM name"

The counterpart to 'vboxmanage.exe' in the VM is Guest Additions' 'vboxcontrol.exe'. You can run vboxcontrol /? in the VM's command line to see its options. 'Vboxcontrol.exe' does not have a method to make a shared folder on the host. That would actually be a pretty big security hole. You can, of course, make a folder shared by the VM's OS over the VM's Bridged or Host-Only network.

However, it wouldn't really be necessary to make a transient shared folder, unless your project is bigger than the portion stated in your post. A regular permanent shared folder would work for file sharing, too.
Post Reply