[APORTE] [VBS] VMWare: Mount / Unmount Shared Folders Network Drive

Páginas: (1/1)

Eleкtro:

Los siguientes dos scripts, desarrollados en el lenguaje Visual Basic Script y que se deben usar en conjunto con una máquina virtual de VMWare (aunque se pueden modificar para Virtual Box), sirven como atajo para montar y desmontar la unidad de red de las "carpetas compartidas" (shared folders).

Utilizar estos scripts nos ahorra un valioso tiempo al no tener que usar el cliente de VMWare para abrir el menú de opciones donde desactivar y reactivar las carpetas compartidas.

La idea tras esta simple herramienta es eso, ahorrar tiempo, y de esta manera poder aislar la máquina virtual del sistema operativo anfitrión impidiendo el acceso a la unidad de red de las carpetas compartidas, y volver a habilitar el acceso, tan solo haciendo dos clicks para ejecutar estos scripts.


Mount Shared Folders Network Drive.vbs
Código
--
' Mount VMWare Shared Folders Network Drive
--
 
--
Option Explicit
--
 
--
Dim objFSO, objShell, objNetwork, colDrives, colNetDrives, i, msg
--
Dim objDrive, vmWareDrive, vmWarePath, drive, path
--
 
--
vmWareDrive = "Z:"
--
vmWarePath  = "\\vmware-host\Shared Folders"
--
 
--
Set objFSO = CreateObject("Scripting.FileSystemObject")
--
Set objShell = CreateObject("WScript.Shell")
--
Set objNetwork = CreateObject("WScript.Network")
--
Set colDrives = objFSO.Drives
--
Set colNetDrives = objNetwork.EnumNetworkDrives
--
 
--
For i = 0 to colNetDrives.Count - 1 Step 2
--
drive = colNetDrives.Item(i)
--
path  = colNetDrives.Item(i+1)
--
 
--
If (LCase(drive) = LCase(vmWareDrive)) Then
--
If (LCase(path) = LCase(vmWarePath)) Then
--
msg = "A network drive is already mounted with same letter and UNC path:" & vbCrLf & vbCrLf
--
msg = msg & drive & vbTab & """" & path & """"
--
objShell.Popup msg, 20, "Warning: Network Drives", 48
--
Else
--
msg = "A network drive is already mounted with a different UNC path:" & vbCrLf & vbCrLf
--
msg = msg & drive & vbTab & """" & path & """"
--
objShell.Popup msg, 20, "Error: Network Drives", 16
--
End If
--
WScript.Quit()
--
End If
--
Next
--
 
--
For Each objDrive in colDrives
--
drive = objDrive.DriveLetter & ":"
--
If (LCase(drive) = LCase(vmWareDrive)) Then
--
msg = "A local drive is already mounted with the same drive letter:" & vbCrLf & vbCrLf
--
msg = msg & "Letter: " & drive & vbCrLf
--
msg = msg & "FileSystem: " & objDrive.FileSystem & vbCrLf
--
msg = msg & "Volume Name: " & objDrive.VolumeName & vbCrLf
--
msg = msg & "Share Name: " & objDrive.ShareName
--
objShell.Popup msg, 20, "Error: Network Drives", 16
--
WScript.Quit()
--
End If
--
Next
--
 
--
objNetwork.MapNetworkDrive vmWareDrive, vmWarePath
--
 
--
msg = "The following network drive was successfully mounted:" & vbCrLf & vbCrLf
--
msg = msg & vmWareDrive & vbTab & """" & vmWarePath & """"
--
objShell.Popup msg, 20, "Info: Network Drives", 64
--
WScript.Quit()
--


Unmount Shared Folders Network Drive.vbs
Código
--
' Unmount VMWare Shared Folders Network Drive
--
 
--
Option Explicit
--
 
--
Dim objShell, objNetwork, colDrives, i, msg
--
Dim vmWareDrive, vmWarePath, drive, path
--
 
--
vmWareDrive = "Z:"
--
vmWarePath  = "\\vmware-host\Shared Folders"
--
 
--
Set objShell = CreateObject("WScript.Shell")
--
Set objNetwork = CreateObject("WScript.Network")
--
Set colDrives = objNetwork.EnumNetworkDrives
--
 
--
For i = 0 to colDrives.Count - 1 Step 2
--
drive = colDrives.Item(i)
--
path  = colDrives.Item(i+1)
--
 
--
If (LCase(drive) = LCase(vmWareDrive)) Then
--
If (LCase(path) = LCase(vmWarePath)) Then
--
objNetwork.RemoveNetworkDrive vmWareDrive, True, True
--
 
--
msg = "The following network drive was successfully unmounted:" & vbCrLf & vbCrLf
--
msg = msg & drive & vbTab & """" & path & """"
--
objShell.Popup msg, 20, "Info: Network Drives", 64
--
Else
--
msg = "A network drive is already mounted with a different UNC path:" & vbCrLf & vbCrLf
--
msg = msg & drive & vbTab & """" & path & """"
--
objShell.Popup msg, 20, "Warning: Network Drives", 16
--
End If
--
WScript.Quit()
--
End If
--
Next
--
 
--
msg = "No matching network drive " & """" & vmWareDrive & """" & " was found."
--
objShell.Popup msg, 20, "Error: Network Drives", 16
--
WScript.Quit()
--


Páginas: (1/1)