Name
VMAddSharedFolder
Description
$err = VMAddSharedFolder($vmHandle,
$shareName,
$hostPathName,
$flags);
This function mounts a new shared folder in the virtual machine.
Parameters
- vmHandle
-
Identifies a virtual machine. Call VMOpen() to create a virtual machine handle.
- shareName
-
Specifies the guest path name of the new shared folder.
- hostPathName
-
Specifies the host path of the shared folder.
- flags
-
The folder options.
Return Value
$err. The error code returned by the operation. For returned values, see Topics > Error Codes.
Remarks
- This function creates a local mount point in the guest file system and
mounts a shared folder exported by the host.
- Shared folders will only be accessible inside the guest operating system if
shared folders are enabled for the virtual machine. See the documentation
for VMEnableSharedFolders().
- The folder options include:
- VIX_SHAREDFOLDER_WRITE_ACCESS - Allow write access.
- Only absolute paths should be used for files in the guest; the resolution of
relative paths is not specified.
- The hostPathName argument must specify a path to a directory that exists on
the host, or an error will result.
- If a shared folder with the same name exists before calling this function,
the function will return VIX_E_ALREADY_EXISTS.
- It is not necessary to call VMLoginInGuest() before calling this function.
- When creating shared folders in a Windows guest, there might be a delay
before contents of a shared folder are visible to functions such as
VMFileExistsInGuest and VMRunProgramInGuest.
- Shared folders are not supported for the following guest operating systems:
Windows ME, Windows 98, Windows 95, Windows 3.x, and DOS.
- In this release, this function requires the virtual machine to be powered on
with VMware Tools installed.
- To determine in which directory in the guest the shared folder will be,
query the VIX_PROPERTY_GUEST_SHAREDFOLDERS_SHARES_PATH property
on the virtual machine handle. When the virtual machine is powered on and
the VMware Tools are running, this property will contain the path to the
parent directory of the shared folders for that virtual machine.
Side Effects
None.
Requirements
use VMware::Vix::Simple;
use VMware::Vix::API::Constants;
since VMware Workstation 6.0
Example
This example shows how to power on a virtual machine, wait until the VMware
Tool are running in the guest, add a shared folder named "WorkDir", and then
run a program that resides inside that shared folder in the guest.
my $err;
my $sharesPath;
my $guestPath;
$err = VMPowerOn($vmHandle,
0, # powerOnOptions
VIX_INVALID_HANDLE); # propertyListHandle
die "VMPowerOn() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK;
$err = VMWaitForToolsInGuest($vmHandle,
300); # timeoutInSeconds
die "VMWaitForToolsInGuest() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK;
$err = VMAddSharedFolder($vmHandle,
"WorkDir",
"/work",
VIX_SHAREDFOLDER_WRITE_ACCESS);
$err = VMLoginInGuest($vmHandle,
"vixuser", # userName
"secret", # password
0); # options
die "VMLoginInGuest() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK;
($err, $sharesPath) = GetProperties($vmHandle,
VIX_PROPERTY_GUEST_SHAREDFOLDERS_SHARES_PATH);
die "GetProperties() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK;
# Build the path to the program in the guest.
$guestPath = $sharesPath . "/" . "WorkDir" . "/" . "myApp";
# Run the target program.
$err = VMRunProgramInGuest($vmHandle,
$guestPath,
"--flag arg1 arg2",
0, # options
VIX_INVALID_HANDLE);
die "VMRunProgramInGuest() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK;
$err = VMLogoutFromGuest($vmHandle);
die "VMLogoutFromGuest() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK;