# Name

VixVM_AddSharedFolder

# Description

    VixHandle
    VixVM_AddSharedFolder(VixHandle vmHandle,
                          const char *shareName,
                          const char *hostPathName,
                          VixMsgSharedFolderOptions flags,
                          VixEventProc *callbackProc,
                          void *clientData);

This function mounts a new shared folder in the virtual machine.

# Parameters

vmHandle
  Identifies a virtual machine. Call VixVM_Open() 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.
callbackProc
  A callback function that will be invoked when the operation is complete.
clientData
  A parameter that will be passed to the callbackProc function.

# Return Value

VixHandle. A job handle that describes the state of this asynchronous operation.

# 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 VixVM_EnableSharedFolders().
- 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 job handle returned by this function will return VIX_E_ALREADY_EXISTS.
- It is not necessary to call VixVM_LoginInGuest() 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 VixVM_FileExistsInGuest and VixVM_RunProgramInGuest.
- 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

vix.h, since VMware Workstation 6.0, not available on Server 2.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 the shared folder in the guest.

    VixHandle jobHandle;
    VixError err;
    const char shareName[] = "WorkDir";
    const char programExecutableName[] = "myApp";
    char *sharesPath;
    char *guestPath;
    size_t guestPathLength;

    jobHandle = VixVM_PowerOn(vmHandle,
                              VIX_VMPOWEROP_NORMAL,
                              VIX_INVALID_HANDLE,
                              NULL,
                              NULL);
    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
    Vix_ReleaseHandle(jobHandle);
    if (VIX_OK != err) {
       // handle error
    }

    jobHandle = VixVM_WaitForToolsInGuest(vmHandle,
                                          180,
                                          NULL,
                                          NULL);
    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
    Vix_ReleaseHandle(jobHandle);
    if (VIX_OK != err) {
       // handle error
    }

    jobHandle = VixVM_AddSharedFolder(vmHandle,
                                      shareName,
                                      "/work",
                                      VIX_SHAREDFOLDER_WRITE_ACCESS,
                                      NULL, NULL);
    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
    Vix_ReleaseHandle(jobHandle);
    if (VIX_OK != err) {
       // handle error
    }

    jobHandle = VixVM_LoginInGuest(vmHandle,
                                   "user",
                                   "password",
                                   0,
                                   NULL,
                                   NULL);
    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
    Vix_ReleaseHandle(jobHandle);
    if (VIX_OK != err) {
       // handle error
    }

    err = Vix_GetProperties(vmHandle,
                            VIX_PROPERTY_GUEST_SHAREDFOLDERS_SHARES_PATH,
                            &sharesPath,
                            VIX_PROPERTY_NONE);
    if (VIX_OK != err) {
       // handle error
    }

    guestPathLength = strlen(sharesPath) + 1 +            // + 1 for '/'
                      strlen(shareName) + 1 +             // + 1 for '/'
                      strlen(programExecutableName) + 1;  // + 1 for '\0'
    guestPath = malloc(guestPathLength);

    snprintf(guestPath, guestPathLength, "%s/%s/%s",
             sharesPath, shareName, programExecutableName);

    Vix_FreeBuffer(sharesPath);

    jobHandle = VixVM_RunProgramInGuest(vmHandle,
                                        guestPath,
                                        "",
                                        0,
                                        VIX_INVALID_HANDLE,
                                        NULL,
                                        NULL);
    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
    Vix_ReleaseHandle(jobHandle);
    if (VIX_OK != err) {
       free(guestPath);
       guestPath = NULL;
       // handle error
    }

    free(guestPath);

    jobHandle = VixVM_LogoutFromGuest(vmHandle,
                                      NULL,
                                      NULL);
    Vix_ReleaseHandle(jobHandle);
    if (VIX_OK != err) {
       free(guestPath);
       // handle error
    }

Copyright (C) 2007-2018 VMware, Inc. All rights reserved.