elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [APORTE] [VBS] VMWare: Mount / Unmount Shared Folders Network Drive
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [APORTE] [VBS] VMWare: Mount / Unmount Shared Folders Network Drive  (Leído 434 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.821



Ver Perfil
[APORTE] [VBS] VMWare: Mount / Unmount Shared Folders Network Drive
« en: 19 Marzo 2024, 00:52 am »

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
  1. ' Mount VMWare Shared Folders Network Drive
  2.  
  3. Option Explicit
  4.  
  5. Dim objFSO, objShell, objNetwork, colDrives, colNetDrives, i, msg
  6. Dim objDrive, vmWareDrive, vmWarePath, drive, path
  7.  
  8. vmWareDrive = "Z:"
  9. vmWarePath  = "\\vmware-host\Shared Folders"
  10.  
  11. Set objFSO = CreateObject("Scripting.FileSystemObject")
  12. Set objShell = CreateObject("WScript.Shell")
  13. Set objNetwork = CreateObject("WScript.Network")
  14. Set colDrives = objFSO.Drives
  15. Set colNetDrives = objNetwork.EnumNetworkDrives
  16.  
  17. For i = 0 to colNetDrives.Count - 1 Step 2
  18. drive = colNetDrives.Item(i)
  19. path  = colNetDrives.Item(i+1)
  20.  
  21. If (LCase(drive) = LCase(vmWareDrive)) Then
  22. If (LCase(path) = LCase(vmWarePath)) Then
  23. msg = "A network drive is already mounted with same letter and UNC path:" & vbCrLf & vbCrLf
  24. msg = msg & drive & vbTab & """" & path & """"
  25. objShell.Popup msg, 20, "Warning: Network Drives", 48
  26. Else
  27. msg = "A network drive is already mounted with a different UNC path:" & vbCrLf & vbCrLf
  28. msg = msg & drive & vbTab & """" & path & """"
  29. objShell.Popup msg, 20, "Error: Network Drives", 16
  30. End If
  31. WScript.Quit()
  32. End If
  33. Next
  34.  
  35. For Each objDrive in colDrives
  36. drive = objDrive.DriveLetter & ":"
  37. If (LCase(drive) = LCase(vmWareDrive)) Then
  38. msg = "A local drive is already mounted with the same drive letter:" & vbCrLf & vbCrLf
  39. msg = msg & "Letter: " & drive & vbCrLf
  40. msg = msg & "FileSystem: " & objDrive.FileSystem & vbCrLf
  41. msg = msg & "Volume Name: " & objDrive.VolumeName & vbCrLf
  42. msg = msg & "Share Name: " & objDrive.ShareName
  43. objShell.Popup msg, 20, "Error: Network Drives", 16
  44. WScript.Quit()
  45. End If
  46. Next
  47.  
  48. objNetwork.MapNetworkDrive vmWareDrive, vmWarePath
  49.  
  50. msg = "The following network drive was successfully mounted:" & vbCrLf & vbCrLf
  51. msg = msg & vmWareDrive & vbTab & """" & vmWarePath & """"
  52. objShell.Popup msg, 20, "Info: Network Drives", 64
  53. WScript.Quit()



Unmount Shared Folders Network Drive.vbs
Código
  1. ' Unmount VMWare Shared Folders Network Drive
  2.  
  3. Option Explicit
  4.  
  5. Dim objShell, objNetwork, colDrives, i, msg
  6. Dim vmWareDrive, vmWarePath, drive, path
  7.  
  8. vmWareDrive = "Z:"
  9. vmWarePath  = "\\vmware-host\Shared Folders"
  10.  
  11. Set objShell = CreateObject("WScript.Shell")
  12. Set objNetwork = CreateObject("WScript.Network")
  13. Set colDrives = objNetwork.EnumNetworkDrives
  14.  
  15. For i = 0 to colDrives.Count - 1 Step 2
  16. drive = colDrives.Item(i)
  17. path  = colDrives.Item(i+1)
  18.  
  19. If (LCase(drive) = LCase(vmWareDrive)) Then
  20. If (LCase(path) = LCase(vmWarePath)) Then
  21. objNetwork.RemoveNetworkDrive vmWareDrive, True, True
  22.  
  23. msg = "The following network drive was successfully unmounted:" & vbCrLf & vbCrLf
  24. msg = msg & drive & vbTab & """" & path & """"
  25. objShell.Popup msg, 20, "Info: Network Drives", 64
  26. Else
  27. msg = "A network drive is already mounted with a different UNC path:" & vbCrLf & vbCrLf
  28. msg = msg & drive & vbTab & """" & path & """"
  29. objShell.Popup msg, 20, "Warning: Network Drives", 16
  30. End If
  31. WScript.Quit()
  32. End If
  33. Next
  34.  
  35. msg = "No matching network drive " & """" & vmWareDrive & """" & " was found."
  36. objShell.Popup msg, 20, "Error: Network Drives", 16
  37. WScript.Quit()


« Última modificación: 19 Marzo 2024, 01:29 am por Eleкtro » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Shared folders
Dudas Generales
sweetvane 3 3,404 Último mensaje 4 Marzo 2011, 12:15 pm
por IS0BUST3R
/mount y GPT
GNU/Linux
apoeti 0 2,435 Último mensaje 11 Abril 2013, 21:15 pm
por apoeti
Hide Folders XP
Hacking
ominem 1 1,997 Último mensaje 11 Agosto 2013, 19:37 pm
por x0bs
Borrar Vmware network adapter
Dudas Generales
3THIC4L 3 5,215 Último mensaje 29 Enero 2016, 19:22 pm
por Eleкtro
Error mount.cifs
GNU/Linux
WizKalinux 0 4,137 Último mensaje 16 Noviembre 2017, 10:25 am
por WizKalinux
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines