Just so we are clear on terminology:
- Full path: The path including the filename and extension, e.g. C:\Path\To\My\Vm\Vm.vbox
- VM path: The path excluding the filename and extension, but including the base directory of the VM, e.g. C:\Path\To\My\Vm
- Base path: The path excluding the filename and extension and the VM directory, e.g. C:\Path\To\My
AdityaM wrote:If I try to understand it correctly, when you say "If you want to create that VM in another directory as a one-off, you can either supply whatever path you want" Does that mean I can give the absolute path (like maybe "C:\Program Files") as first argument to the createMachine() function. Because I tried doing so and it was failing.
The first argument must be the full path, not the VM or Base path. If it still fails, please give the exact error code and full error message associated with it.
AdityaM wrote:Also please correct my understanding if I am wrong - that according to SDKref documentation createMachine() function Creates a new virtual machine by creating a machine settings file at the given location; so if I am passing NULL to this function as first argument; then after the function is executed I should be able to see a .VBOX (Settings File) at ..\users\username\VirtualBox VMs\VBox name folder, but it is not so. I am not able to see any new file or folder created after the createMachine() function is executed.
The first sentence is missleading. If you read further, the steps of how you would create a VM are clearly explained and the step #3 states that the settings file will not be created until you call
IMachine::saveSettings.
So up to that point, the IMachine object is only in memory.
AdityaM wrote:
But as per your reply " I would recommend simply changing ISystemProperties::defaultMachineFolder to another location (and revert it back afterwards if needed)" I would like to try out this strategy. So what I would like to do is something like below pseudo code -
Code: Select all
//get the default Machine folder; and store it in some variable
ISystemProperties::get_DefaultMachineFolder (def_path);
//change the the default Machine folder (assuming the path for location of new VM to be created is stored in new_path)
ISystemProperties::put_DefaultMachineFolder (new_path);
//now create the new VM
rc = virtualBox->CreateMachine(NULL, machineClonedName,NULL,NULL,NULL,&machineClone); //Working
if (!FAILED(rc))
{
rc = machine->CloneTo(machineClone,mode,NULL,&progress);
}
//and now restore the value of Default machine folder to its original
ISystemProperties::put_DefaultMachineFolder (def_path);
Do you think this would work? Can I do this (changing the Default Machine Folder in settings file ) at run-time i.e even when Virtual Box is running?
Please suggest.
Yes this would work and yes you can change the default machine folder while VirtualBox and/or VMs are running.
AdityaM wrote:Another thing that I would like to mention is that I was not able to use "ISystemProperties::get_DefaultMachineFolder " API as it was giving some error. So any suggestions on that as well would be appreciated.
Without the exact error code and message, we cannot help I'm afraid.
AdityaM wrote:Pardon me for asking these questions to so much details, but I am new to using Oracle Virtual Box APIs and am trying to learn them.
There is nothing to pardon, that's what this forum is for! Ask away all the questions you want. I would just ask you to keep questions in related topics. If you have questions not related to create a VM at a different location than the default part but to another specific task you want to perform, just make a topic for it.
Or if you want to ask general questions spanning several topics, just create a topic called "questions about API" or something like that
It will help new comers like you to find specific answers to specific questions.
If you would like sample code to help you on how to achieve something, you can have a look
here if one already exists or you can just ask me directly and I'll write it (in Java)