No merece la pena hacer esto en Batch, de hecho no merece la pena usar Batch para casi ninguna cosa, pero respondiendo a tu pregunta aquí tienes:
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúCita de: #!drvy en 9 Mayo 2018, 20:02 PM33 años después de ser creado
Cita de: NEBIRE en 9 Mayo 2018, 01:47 AMUna búsqeuda rápida me ofrece este pdf, que puede servirte... (no lo he descargado).
https://www.vmware.com/support/developer/vix-api/vix170_vmrun_command.pdf
''' <summary>
''' Represents the username/password login data for the running guest operating system of a VMWare's virtual machine.
''' </summary>
Public NotInheritable Class GuestOsCredential
#Region " Properties "
''' <summary>
''' Gets or sets the account username.
''' </summary>
Public Property Username As String
''' <summary>
''' Gets or sets the account password.
''' </summary>
Public Property Password As String
#End Region
#Region " Constructors "
''' <summary>
''' Initializes a new instance of the <see cref="GuestOsCredential"/> class.
''' </summary>
Public Sub New()
End Sub
#End Region
End Class
''' <summary>
''' Specifies the behavior of a program that is executed by VMWare's vmrun.exe application.
''' </summary>
<Flags>
Public Enum VmRunProgramFlags
''' <summary>
''' Run the program using the default behavior.
''' </summary>
None = 1
''' <summary>
''' Returns a prompt immediately after the program starts in the guest operating system, rather than waiting for it to finish.
''' <para></para>
''' This option is useful for interactive programs.
''' </summary>
NoWait = 2
''' <summary>
''' Ensures that the program window is visible, not minimized, in the guest operating system.
''' <para></para>
''' This option has no effect on Linux.
''' </summary>
ActiveWindow = 4
''' <summary>
''' Forces interactive guest login.
''' <para></para>
''' This option is useful for Windows VISTA guests to make the program visible in he console window.
''' </summary>
Interactive = 8
End Enum
''' <summary>
''' The exception that Is thrown When a call to VMWare's vmrun.exe application exits with an error.
''' </summary>
<Serializable>
<XmlRoot(NameOf(VmRunException))>
<ImmutableObject(True)>
Public NotInheritable Class VmRunException : Inherits Exception
#Region " Properties "
''' <summary>
''' Gets the exit code of VMWare's vmrun.exe application.
''' </summary>
Public ReadOnly Property ExitCode As Integer
#End Region
#Region " Constructors "
''' <summary>
''' Prevents a default instance of the <see cref="VmRunException"/> class from being created.
''' </summary>
Private Sub New()
End Sub
''' <summary>
''' Initializes a new instance of the System.Exception class with a specified error message.
''' </summary>
''' <param name="message">
''' The message that describes the error.
''' </param>
<DebuggerNonUserCode>
<EditorBrowsable(EditorBrowsableState.Never)>
Private Sub New(ByVal message As String)
MyBase.New(message)
End Sub
''' <summary>
''' Initializes a new instance of the System.Exception class with a specified error message
''' and a reference to the inner exception that is the cause of this exception.
''' </summary>
''' <param name="message">
''' The message that describes the error.
''' </param>
'''
''' <param name="innerException">
''' The exception that is the cause of the current exception,
''' or <see langword="Nothing"/> if no inner exception is specified.
''' </param>
<DebuggerNonUserCode>
<EditorBrowsable(EditorBrowsableState.Never)>
Private Sub New(ByVal message As String, ByVal innerException As Exception)
MyBase.New(message, innerException)
End Sub
''' <summary>
''' Initializes a new instance of the System.Exception class with a specified error message and exit code.
''' </summary>
''' <param name="message">
''' The error message thrown by VMWare's vmrun.exe application.
''' </param>
'''
''' <param name="exitCode">
''' The exit code of VMWare's vmrun.exe application
''' </param>
Public Sub New(ByVal message As String, ByVal exitCode As Integer)
MyBase.New(message)
Me.ExitCode = exitCode
End Sub
#End Region
End Class
''' <summary>
''' Represents a shared folder of a VMWare's virtual machine.
''' </summary>
Public NotInheritable Class VmSharedFolderInfo
#Region " Properties "
''' <summary>
''' Gets or sets the share name.
''' </summary>
Public Property Name As String
''' <summary>
''' Gets or sets the shared directory on host operating system.
''' </summary>
Public Property HostDirectory As DirectoryInfo
''' <summary>
''' Gets or sets a value that determine whether this shared folder is enabled.
''' </summary>
Public Property Enabled As Boolean
''' <summary>
''' Gets or sets a value that determine whether this shared folder allows read access.
''' </summary>
Public Property ReadAccess As Boolean
''' <summary>
''' Gets or sets a value that determine whether this shared folder allows write access.
''' </summary>
Public Property WriteAccess As Boolean
''' <summary>
''' Gets or sets the expiration time of this shared folder.
''' </summary>
Public Property Expiration As String
#End Region
#Region " Constructors "
''' <summary>
''' Initializes a new instance of the <see cref="VmSharedFolderInfo"/> class.
''' </summary>
Public Sub New()
End Sub
#End Region
End Class
''' <summary>
''' Represents a VMWare Virtual Machine.
''' </summary>
Public NotInheritable Class VMWareVirtualMachine
#Region " Properties "
''' <summary>
''' Gets .vmx file of this VM.
''' </summary>
Public ReadOnly Property VmxFile As FileInfo
''' <summary>
''' Gets or sets the username and password of the running user-account in the guest operating system of this VM.
''' <para></para>
''' The credential is required to perform some I/O operations with VMWare's vmrun.exe program.
''' So you must set this credential before using vmrun.exe.
''' </summary>
Public Property GuestOsCredential As GuestOsCredential
''' <summary>
''' Gets a value that determine whether this VM is a shared VM.
''' </summary>
Public ReadOnly Property IsSharedVm As Boolean
''' <summary>
''' Gets the display name of this VM.
''' </summary>
Public ReadOnly Property DisplayName As String
Get
Return Me.displayNameB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the display name of this VM.
''' </summary>
Private displayNameB As String
''' <summary>
''' Gets the version of the guest operating system of this VM.
''' </summary>
Public ReadOnly Property OsVersion As String
Get
Return Me.osVersionB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the version of the guest operating system of this VM.
''' </summary>
Private osVersionB As String
''' <summary>
''' Gets the firmware type of this VM. It can be: BIOS, or UEFI.
''' </summary>
Public ReadOnly Property Firmware As String
Get
Return Me.firmwareB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the firmware type of this VM. It can be: BIOS, or UEFI.
''' </summary>
Private firmwareB As String
''' <summary>
''' Gets a value that determine whether secureboot is enabled for UEFI firmware mode.
''' </summary>
Public ReadOnly Property SecureBootEnabled As Boolean
Get
Return Me.secureBootEnabledB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets a value that determine whether secureboot is enabled for UEFI firmware mode.
''' </summary>
Private secureBootEnabledB As Boolean
''' <summary>
''' Gets the hardware version of this VM.
''' </summary>
''' <remarks>
''' See for more info about virtual machine hardware versions: <see href="https://kb.vmware.com/s/article/1003746"/>
''' </remarks>
Public ReadOnly Property VmHardwareVersion As Integer
Get
Return Me.vmHardwareVersionB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the hardware version of this VM.
''' </summary>
Private vmHardwareVersionB As Integer
''' <summary>
''' Gets the total memory size of this VM, in megabytes.
''' </summary>
Public ReadOnly Property MemorySize As Integer
Get
Return Me.memorySizeB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the total memory size of this VM, in megabytes.
''' </summary>
Private memorySizeB As Integer
''' <summary>
''' Gets the total graphics memory size of this VM, in megabytes.
''' </summary>
Public ReadOnly Property GraphicsMemorySize As Integer
Get
Return Me.graphicsMemorySizeB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the total graphics memory size of this VM, in megabytes.
''' </summary>
Private graphicsMemorySizeB As Integer
''' <summary>
''' Gets a value that determine whether 3D graphics hardware acceleration is enabled in this VM.
''' </summary>
Public ReadOnly Property GraphicsHardwareAccelerationEnabled As Boolean
Get
Return Me.graphicsHardwareAccelerationEnabledB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets a value that determine whether 3D graphics hardware acceleration is enabled in this VM.
''' </summary>
Private graphicsHardwareAccelerationEnabledB As Boolean
''' <summary>
''' Gets the amount of processor cores of this VM.
''' </summary>
Public ReadOnly Property TotalProcessorCores As Integer
Get
Return Me.totalProcessorCoresB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the amount of processor cores of this VM.
''' </summary>
Private totalProcessorCoresB As Integer
''' <summary>
''' Gets the amount of cores per processor of this VM.
''' </summary>
Public ReadOnly Property CoresPerProcessor As Integer
Get
Return Me.coresPerProcessorB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the amount of cores per processor of this VM.
''' </summary>
Private coresPerProcessorB As Integer
''' <summary>
''' Gets the amount of processors of this VM.
''' <para></para>
''' The resulting value is the division between <see cref="VMWareVirtualMachine.TotalProcessorCores"/> \ <see cref="VMWareVirtualMachine.CoresPerProcessor"/>.
''' </summary>
Public ReadOnly Property ProcessorCount As Integer
Get
Return (Me.TotalProcessorCores \ Me.CoresPerProcessor)
End Get
End Property
''' <summary>
''' Gets the shared folders of this VM.
''' </summary>
Public ReadOnly Property SharedFolders As ReadOnlyCollection(Of VmSharedFolderInfo)
Get
Return Me.sharedFoldersB
End Get
End Property
''' <summary>
''' ( Backing Fields )
''' <para></para>
''' Gets the shared folders of this VM.
''' </summary>
Private sharedFoldersB As ReadOnlyCollection(Of VmSharedFolderInfo)
#End Region
#Region " Constructors "
''' <summary>
''' Prevents a default instance of the <see cref="VMWareVirtualMachine"/> class from being created.
''' </summary>
Private Sub New()
End Sub
''' <summary>
''' Initializes a new instance of the <see cref="VMWareVirtualMachine"/> class.
''' </summary>
''' <param name="vmxFilePath">
''' The full path to the .vmx file.
''' </param>
'''
''' <param name="isSharedVm">
''' A value that determine whether the VM is a shared VM.
''' </param>
Public Sub New(ByVal vmxFilePath As String, ByVal isSharedVm As Boolean)
Me.VmxFile = New FileInfo(vmxFilePath)
Me.IsSharedVm = isSharedVm
Me.GuestOsCredential = New GuestOsCredential()
Me.Refresh()
End Sub
#End Region
#Region " Public Methods "
''' <summary>
''' Refresh the state (the properties) of this <see cref="VMWareVirtualMachine"/>.
''' </summary>
''' <exception cref="FileNotFoundException">
''' .vmx file not found.
''' </exception>
Public Sub Refresh()
If Not (Me.VmxFile.Exists) Then
Throw New FileNotFoundException(".vmx file not found.", Me.VmxFile.FullName)
End If
Me.VmxFile.Refresh()
Dim sharedFoldersDict As New Dictionary(Of String, VmSharedFolderInfo)
Using sr As StreamReader = Me.VmxFile.OpenText()
Dim line As String
Do Until sr.EndOfStream
line = sr.ReadLine().Trim()
Select Case True
Case line.ToLower().StartsWith("displayname")
Me.displayNameB = line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote})
Case line.ToLower().StartsWith("firmware")
Me.firmwareB = line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote})
Case line.ToLower().StartsWith("guestos")
Me.osVersionB = line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote})
Case line.ToLower().StartsWith("memsize")
Me.memorySizeB = CInt(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower().StartsWith("numvcpus")
Me.totalProcessorCoresB = CInt(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower().StartsWith("cpuid.corespersocket")
Me.coresPerProcessorB = CInt(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower().StartsWith("svga.graphicsmemorykb")
Me.graphicsMemorySizeB = (CInt(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote})) \ 1000)
Case line.ToLower().StartsWith("virtualhw.version")
Me.vmHardwareVersionB = CInt(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower().StartsWith("uefi.secureboot.enabled")
Me.secureBootEnabledB = Boolean.Parse(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower().StartsWith("mks.enable3d")
Me.graphicsHardwareAccelerationEnabledB = Boolean.Parse(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower() Like "sharedfolder#*.?*"
Me.ParseSharedFolderLine(line, sharedFoldersDict)
End Select
Loop
End Using
Me.sharedFoldersB = New ReadOnlyCollection(Of VmSharedFolderInfo)(sharedFoldersDict.Values.ToArray())
sharedFoldersDict.Clear()
End Sub
#End Region
#Region " Private Methods "
''' <summary>
''' Parses a line of the .vmx file that contains a shared folder field and value.
''' </summary>
''' <param name="line">
''' The line to parse.
''' </param>
'''
''' <param name="refSharedFoldersDict">
''' A <see cref="Dictionary(Of String, SharedFolderInfo)"/> that will be used to set the corresponding <see cref="VmSharedFolderInfo"/> member.
''' </param>
Private Sub ParseSharedFolderLine(ByVal line As String, ByRef refSharedFoldersDict As Dictionary(Of String, VmSharedFolderInfo))
Dim key As String = line.ToLower().Substring(0, line.IndexOf("."c))
If Not refSharedFoldersDict.ContainsKey(key) Then
refSharedFoldersDict.Add(key, New VmSharedFolderInfo())
End If
Select Case True
Case line.ToLower() Like "sharedfolder#*.enabled*"
refSharedFoldersDict(key).Enabled = Boolean.Parse(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower() Like "sharedfolder#*.expiration*"
refSharedFoldersDict(key).Expiration = line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote})
Case line.ToLower() Like "sharedfolder#*.guestname*"
refSharedFoldersDict(key).Name = line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote})
Case line.ToLower() Like "sharedfolder#*.hostpath*"
refSharedFoldersDict(key).HostDirectory = New DirectoryInfo(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower() Like "sharedfolder#*.readaccess*"
refSharedFoldersDict(key).ReadAccess = Boolean.Parse(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
Case line.ToLower() Like "sharedfolder#*.writeaccess*"
refSharedFoldersDict(key).WriteAccess = Boolean.Parse(line.Substring(line.IndexOf("="c) + 1).Trim({" "c, ControlChars.Quote}))
End Select
End Sub
#End Region
End Class
'***********************************************************************************************************************************
'
'This is a code example that demonstrates how to get the running virtual machines, then run a program on each guest operating system.
'
'***********************************************************************************************************************************
Private vmRun As VmRunWrapper
Private Async Sub Test()
Me.vmRun = New VmRunWrapper("C:\Program Files (x86)\VMWare\VMware VIX\vmrun.exe")
Dim vmCount As Integer = Await Me.vmRun.GetRunningVmCountAsync()
If (vmCount > 0) Then
Dim vms As ReadOnlyCollection(Of VMWareVirtualMachine) = Await Me.vmRun.GetRunningVmsAsync()
For Each vm As VMWareVirtualMachine In vms
' Check whether VMWare-Tools are installed in the VM.
' The VmWare-Tools are required by some of the functionalities of vmrun.exe program.
Dim isVMWareToolsInstalled As Boolean = Await Me.vmRun.IsVmWareToolsInstalledAsync(vm)
Console.WriteLine("VM Name: {0}; IsVMWareToolsInstalled: {1}'", vm.DisplayName, isVMWareToolsInstalled)
If Not isVMWareToolsInstalled Then
Me.vmRun.InstallVmWareTools(vm)
Continue For
End If
' A valid guest username and password (if any) is required in order to use some of the functionalities of vmrun.exe program.
vm.GuestOsCredential.Username = "guest username"
vm.GuestOsCredential.Password = "guest password"
Try
' Run a random program on the guest operating system.
Me.vmRun.ProcessRun(vm, "C:\program.exe", VmRunProgramFlags.NoWait Or VmRunProgramFlags.ActiveWindow Or VmRunProgramFlags.Interactive, "")
Catch ex As VmRunException
Throw
Catch ex As Exception
Throw
End Try
Next
End If
End Sub