I've been trying to write Java code to startup and login to a Windows Server 2003 VM. However, it doesnt quite seem to work. I'm using the VIX DLL, and using JNA calls to directly invoke the C API methods.
Here is my sample code:
-
jobHandle = instance.VixHost_Connect(VIX_API_VERSION, VIX_SERVICEPROVIDER_VMWARE_WORKSTATION,
"127.0.0.1" , 0, null, null, 0, VIX_INVALID_HANDLE, null, null);
long result = instance.VixJob_Wait(jobHandle, VIX_PROPERTY_JOB_RESULT_HANDLE, new int[1], VIX_PROPERTY_NONE);
if (result != VIX_OK) {
System.out.println("Error in connecting " + result);
}
instance.Vix_ReleaseHandle(jobHandle);
// Open VM
jobHandle = instance.VixVM_Open(hostHandle[0], vmxPath, null, null);
result = instance.VixJob_Wait(jobHandle, VIX_PROPERTY_JOB_RESULT_HANDLE, new int[1], VIX_PROPERTY_NONE);
if (result != VIX_OK) {
System.out.println("Error in opening VM: " + result);
}
instance.Vix_ReleaseHandle(jobHandle);
// Power On VM
jobHandle = instance.VixVM_PowerOn(vmHandle[0], VIX_VMPOWEROP_LAUNCH_GUI, VIX_INVALID_HANDLE, null, null);
result = instance.VixJob_Wait(jobHandle, VIX_PROPERTY_NONE, new int[1], VIX_PROPERTY_NONE);
if (result != VIX_OK) {
System.out.println("Error in powering VM on: " + result);
}
instance.Vix_ReleaseHandle(jobHandle);
jobHandle = instance.VixVM_LoginInGuest(loginHandle[0], "Administrator", "Password", vmxPath, null, null);
result = instance.VixJob_Wait(jobHandle, VIX_PROPERTY_NONE, new int[1], VIX_PROPERTY_NONE);
if (result != VIX_OK) {
System.out.println("Error in logging in: " + result);
}
instance.Vix_ReleaseHandle(jobHandle);
-
Any java developers out there who might be able to help me figure out why this isnt working right ?
I'm using the VIX sample code as reference. ( http://www.vmware.com/support/developer/vix-api/vix18_reference/lang/c/functions/VixVM_LoginInGuest.html under Examples)
The line marked in BOLD in code, is returning result as 3, instead of VIX_OK (i.e. 0) as expected. VM doesnt even open.
Help would be appreciated.