Common Tasks :Connecting to the Local Host as a Specified User

来源:互联网 发布:巫女服 知乎 编辑:程序博客网 时间:2024/06/06 02:58

This allows your client to run on any host machine running VMware Server that has a given user account. For example, you could create a client script that a system administrator could use on any machine to shut down all virtual machines owned by a given user. The example shown below allows you to choose a user account when you run the script.

This form of connection is supported by VMware Server. If the host is running VMware Workstation, you must use the procedure Connecting to the Local Host as the Current User.

    Example 3-2.
#include "vix.h" int main(int argc, char * argv[]){   VixHandle hostHandle = VIX_INVALID_HANDLE;   VixHandle jobHandle = VIX_INVALID_HANDLE;   VixError err;    // Connect as specified user on local host.   jobHandle = VixHost_Connect(VIX_API_VERSION,                               VIX_SERVICEPROVIDER_VMWARE_SERVER,                               NULL, // hostName                               0, // hostPort                               argv[1], // userName                               argv[2], // password,                               0, // options                               VIX_INVALID_HANDLE, // propertyListHandle                               NULL, // callbackProc                               NULL); // clientData   err = VixJob_Wait(jobHandle,                     VIX_PROPERTY_JOB_RESULT_HANDLE,                     &hostHandle,                     VIX_PROPERTY_NONE);   if (VIX_OK != err) {      // Handle the error...      goto abort;   }   Vix_ReleaseHandle(jobHandle);   jobHandle = VIX_INVALID_HANDLE;   // Other code goes here... abort:   VixHost_Disconnect(hostHandle);}