/* * Runs regedit export of LANDesk software tracking, pulls file from guest -> host and returns number of lines in the file. * */ private static int getRegEntryNum(VMWareVirtualMachine ivm) { if (ivm.FileExistsInGuest(pstempGuest + @"\reg.txt")) { ivm.DeleteFileFromGuest(pstempGuest + @"\reg.txt"); } VMWareVirtualMachine.Process proc = ivm.RunProgramInGuest(@"C:\Windows\System32\Reg.exe", "export \"HKEY_LOCAL_MACHINE\\SOFTWARE\\LANdesk\\SOFTWARE\" \"" + pstempGuest + "\\reg.txt\""); if (File.Exists(workingDir + @"\reg.txt")) { File.Delete(workingDir + @"\reg.txt"); } ivm.CopyFileFromGuestToHost(pstempGuest + @"\reg.txt", workingDir + @"\reg.txt"); return(File.ReadAllLines(workingDir + @"\reg.txt").Length); }
/// <summary> /// /// </summary> /// <returns></returns> public override bool Execute() { using (VMWareVirtualHost host = GetConnectedHost()) { using (VMWareVirtualMachine virtualMachine = OpenVirtualMachine(host)) { LoginGuest(virtualMachine); Log.LogMessage(string.Format("Running '{0}{1}'", _guestProgramName, string.IsNullOrEmpty(_commandLineArgs) ? string.Empty : " " + _commandLineArgs)); _process = virtualMachine.RunProgramInGuest(_guestProgramName, _commandLineArgs, 0, _runProgramTimeout); } } return(true); }
public void GettingStartedWorkstation() { #region Example: Getting Started (Workstation) // declare a virtual host using (VMWareVirtualHost virtualHost = new VMWareVirtualHost()) { // connect to a local VMWare Workstation virtual host virtualHost.ConnectToVMWareWorkstation(); // open an existing virtual machine using (VMWareVirtualMachine virtualMachine = virtualHost.Open(@"C:\Virtual Machines\xp\xp.vmx")) { // power on this virtual machine virtualMachine.PowerOn(); // wait for VMWare Tools virtualMachine.WaitForToolsInGuest(); // login to the virtual machine virtualMachine.LoginInGuest("Administrator", "password"); // run notepad virtualMachine.RunProgramInGuest("notepad.exe", string.Empty); // create a new snapshot string name = "New Snapshot"; // take a snapshot at the current state VMWareSnapshot createdSnapshot = virtualMachine.Snapshots.CreateSnapshot(name, "test snapshot"); createdSnapshot.Dispose(); // power off virtualMachine.PowerOff(); // find the newly created snapshot using (VMWareSnapshot foundSnapshot = virtualMachine.Snapshots.GetNamedSnapshot(name)) { // revert to the new snapshot foundSnapshot.RevertToSnapshot(); // delete snapshot foundSnapshot.RemoveSnapshot(); } } } #endregion }
public void GettingStartedVI() { #region Example: Getting Started (VI) // declare a virtual host using (VMWareVirtualHost virtualHost = new VMWareVirtualHost()) { // connect to a remove (VMWare ESX) virtual machine virtualHost.ConnectToVMWareVIServer("esx.mycompany.com", "vmuser", "password"); // open an existing virtual machine using (VMWareVirtualMachine virtualMachine = virtualHost.Open("[storage] testvm/testvm.vmx")) { // power on this virtual machine virtualMachine.PowerOn(); // wait for VMWare Tools virtualMachine.WaitForToolsInGuest(); // login to the virtual machine virtualMachine.LoginInGuest("Administrator", "password"); // run notepad virtualMachine.RunProgramInGuest("notepad.exe", string.Empty); // create a new snapshot string name = "New Snapshot"; // take a snapshot at the current state virtualMachine.Snapshots.CreateSnapshot(name, "test snapshot"); // power off virtualMachine.PowerOff(); // find the newly created snapshot using (VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot(name)) { // revert to the new snapshot snapshot.RevertToSnapshot(); // delete snapshot snapshot.RemoveSnapshot(); } } } #endregion }
public VMWareVirtualMachine.Process RunProgramInGuest(string path, string parameters, int options) { ConsoleOutput.WriteLine(" Executing 'Remote:{0} {1}'", path, parameters); return(_simulationOnly ? new VMWareVirtualMachine.Process(null) : _vm.RunProgramInGuest(path, parameters, options, VMWareInterop.Timeouts.RunProgramTimeout)); }
/* * Runs regedit export of LANDesk software tracking, pulls file from guest -> host and returns number of lines in the file. * */ private static int getRegEntryNum(VMWareVirtualMachine ivm) { if (ivm.FileExistsInGuest(pstempGuest + @"\reg.txt")) ivm.DeleteFileFromGuest(pstempGuest + @"\reg.txt"); VMWareVirtualMachine.Process proc = ivm.RunProgramInGuest(@"C:\Windows\System32\Reg.exe", "export \"HKEY_LOCAL_MACHINE\\SOFTWARE\\LANdesk\\SOFTWARE\" \"" + pstempGuest + "\\reg.txt\""); if (File.Exists(workingDir + @"\reg.txt")) File.Delete(workingDir + @"\reg.txt"); ivm.CopyFileFromGuestToHost(pstempGuest + @"\reg.txt", workingDir + @"\reg.txt"); return File.ReadAllLines(workingDir + @"\reg.txt").Length; }