@@ -0,0 +1,3047 @@
+package com.vmware.vim25.mo.samples.guestos;%0A%0Aimport java.net.MalformedURLException;%0Aimport java.rmi.RemoteException;%0A%0Aimport com.vmware.vim25.GuestProcessInfo;%0Aimport com.vmware.vim25.GuestProgramSpec;%0Aimport com.vmware.vim25.NamePasswordAuthentication;%0Aimport com.vmware.vim25.mo.Folder;%0Aimport com.vmware.vim25.mo.GuestOperationsManager;%0Aimport com.vmware.vim25.mo.GuestProcessManager;%0Aimport com.vmware.vim25.mo.InventoryNavigator;%0Aimport com.vmware.vim25.mo.ServiceInstance;%0Aimport com.vmware.vim25.mo.VirtualMachine;%0Aimport com.vmware.vim25.mo.samples.SampleUtil;%0A%0Apublic class ChangeGuestOSPassword %7B%0A%0A   public static void main(String%5B%5D args) throws RemoteException, MalformedURLException, InterruptedException %7B%0A      ServiceInstance si = SampleUtil.createServiceInstance();%0A      Folder rootFolder = si.getRootFolder();%0A%0A      String vmName = %22test-vm%22;%0A      VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity(%22VirtualMachine%22,%0A            vmName);%0A      if (vm == null) %7B%0A         System.out.println(%22Can not find VM %22 + vmName);%0A         return;%0A      %7D%0A%0A      GuestOperationsManager gom = si.getGuestOperationsManager();%0A%0A      if (!%22guestToolsRunning%22.equals(vm.getGuest().toolsRunningStatus)) %7B%0A         System.out.println(%22The VMware Tools is not running in the Guest OS on VM %22 + vm.getName());%0A         System.out.println(%22Exiting...%22);%0A         return;%0A      %7D%0A%0A      String osFamily = vm.getGuest().getGuestFamily();%0A      System.out.println(%22osFamily: %22 + osFamily);%0A      boolean isWindows = osFamily.contains(%22windowsGuest%22);%0A      String currentPassword = %22password%22;%0A      String newPassword = %22password%22;%0A      NamePasswordAuthentication creds = new NamePasswordAuthentication();%0A      creds.username = isWindows ? %22Administrator%22 : %22root%22;%0A      creds.password = currentPassword;%0A%0A      GuestProgramSpec spec = new GuestProgramSpec();%0A      if (isWindows) %7B%0A         spec.programPath = %22C:%5C%5CWindows%5C%5CSystem32%5C%5Ccmd.exe%22;%0A         spec.arguments = %22/C net user Administrator %22 + newPassword;%0A      %7D else %7B%0A         spec.programPath = %22/bin/bash%22;%0A         spec.arguments = %22-c 'echo %22 + newPassword + %22 %7C passwd root --stdin'%22;%0A      %7D%0A      GuestProcessManager gpm = gom.getProcessManager(vm);%0A      long pid = -1;%0A      try %7B%0A         pid = gpm.startProgramInGuest(creds, spec);%0A         System.out.println(%22pid: %22 + pid);%0A         Thread.sleep(3000);%0A         creds.password = newPassword;%0A         while (true) %7B%0A            GuestProcessInfo%5B%5D infoList = gpm.listProcessesInGuest(creds, new long%5B%5D %7B pid %7D);%0A            GuestProcessInfo info = infoList%5B0%5D;%0A            if (info.getExitCode() == null) %7B%0A               System.out.println(%22Waiting for the process to exit ... %22);%0A               Thread.sleep(3000);%0A            %7D else %7B%0A               System.out.println(%22exit code: %22 + info.getExitCode());%0A               break;%0A            %7D%0A         %7D%0A      %7D catch (RemoteException e) %7B%0A         e.printStackTrace();%0A      %7D%0A%0A      si.getServerConnection().logout();%0A   %7D%0A%7D%0A

Add sample of changing user password for Windows/Linx guestOS