$err = VMAddSharedFolder($vmHandle,
$shareName,
$hostPathName,
$flags);
This function mounts a new shared folder in the virtual machine.
use VMware::Vix::Simple; use VMware::Vix::API::Constants;since VMware Workstation 6.0
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;