Ejemplo n.º 1
0
        /// <summary>
        /// Read a file in the guest operating system.
        /// </summary>
        /// <param name="guestFilename">File in the guest operating system.</param>
        /// <param name="encoding">Encoding applied to the file contents.</param>
        /// <returns>File contents as a string.</returns>
        public string ReadFile(string guestFilename, Encoding encoding)
        {
            string tempFilename = Path.GetTempFileName();

            try
            {
                _vm.CopyFileFromGuestToHost(guestFilename, tempFilename);
                return(File.ReadAllText(tempFilename, encoding));
            }
            finally
            {
                File.Delete(tempFilename);
            }
        }
Ejemplo n.º 2
0
        public void CopyFileFromGuestToHost(string guestPath, string hostPath, string exclude)
        {
            switch (_copyMethod)
            {
            case CopyMethod.network:
                string guestRootPath = Path.GetPathRoot(guestPath);
                MappedNetworkDriveInfo mappedNetworkDriveInfo = new MappedNetworkDriveInfo(guestRootPath);
                mappedNetworkDriveInfo.Username = _username;
                mappedNetworkDriveInfo.Password = _password;
                mappedNetworkDriveInfo.Auto     = false;
                ConsoleOutput.WriteLine(" Mapping 'Remote:{0}' as '{1}'", mappedNetworkDriveInfo.RemotePath, _username);
                if (!_simulationOnly)
                {
                    using (MappedNetworkDrive mappedNetworkDrive = new MappedNetworkDrive(_vm, mappedNetworkDriveInfo))
                    {
                        string guestNetworkPath     = mappedNetworkDrive.GuestPathToNetworkPath(guestPath);
                        string guestNetworkRootPath = mappedNetworkDrive.GuestPathToNetworkPath(guestRootPath);
                        ConsoleOutput.WriteLine(" Resolving 'Remote:{0}'", guestNetworkRootPath);
                        mappedNetworkDrive.MapNetworkDrive();
                        ConsoleOutput.WriteLine(" Copying 'Remote:{0}' => '{1}'", guestNetworkPath, hostPath);
                        CopyFiles(guestNetworkPath, hostPath, exclude);
                    }
                }
                break;

            case CopyMethod.vmware:
            default:
                ConsoleOutput.WriteLine(" 'Remote:{0}' => '{1}'", guestPath, hostPath);
                if (!_simulationOnly)
                {
                    _vm.CopyFileFromGuestToHost(guestPath, hostPath);
                }
                break;
            }
        }
Ejemplo n.º 3
0
 /*
  * 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);
 }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            using (VMWareVirtualHost host = GetConnectedHost())
            {
                using (VMWareVirtualMachine virtualMachine = OpenVirtualMachine(host))
                {
                    LoginGuest(virtualMachine);
                    Log.LogMessage(string.Format("Copying guest '{0}' to host '{1}'", _guestPathName, _hostPathName));
                    virtualMachine.CopyFileFromGuestToHost(_guestPathName, _hostPathName, _copyFileTimeout);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
 /*
  * 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;
 }