'--------------------------------------------------------------------------------- ' UNIDADES DE RED ' ------------------------------------- ' Autor : Hanok ' Información : http://www.hnkweb.com ' Fecha : 09/2006 '--------------------------------------------------------------------------------- 'DEFINICIÓN DE VARIABLES '--------------------------------------------------------------------------------- Dim WshNet, WshShell, fso, Unidades_de_red, perfil 'Creación del objeto red, el objetoy shell y el acceso a la estructura de ficheros Set WshNet = Wscript.CreateObject("WScript.Network") Set WshShell = WScript.CreateObject("WScript.Shell") Set fso = WScript.CreateObject("Scripting.FileSystemObject") 'Asignación de las unidades de red a una matriz Set unidades_de_red = WshNet.EnumNetworkDrives 'FUNCIONES '--------------------------------------------------------------------------------- Function Nueva_Unidad(unidad,ruta, usuario, password) Dim num num = unidad & ":" On Error Resume Next WshNet.MapNetworkDrive num , ruta, False, usuario, password Nueva_Unidad = Err.Number = 0 End Function Function EnumerarUnidades Set unidades_de_red = WshNet.EnumNetworkDrives If unidades_de_red.count = 0 then msgbox "No hay Unidades de red conectadas.", vbInformation + vbOkOnly Else strMsg = "Conexiones actuales a unidades de red: " & chr(13) For i = 0 To unidades_de_red.Count - 1 Step 2 strMsg = strMsg & chr(13) & unidades_de_red(i) & Chr(9) & Unidades_de_red(i + 1) Next MsgBox strMsg, vbInformation + vbOkOnly End If End Function 'INICIO '--------------------------------------------------------------------------------- Set unidades_de_red = WshNet.EnumNetworkDrives 'Borrar todas las unidad de red, en caso de que el usuario así lo quiera If unidades_de_red.count > 0 then borrar = msgbox("¿Borramos todas las Unidades de red?", vbQuestion+vbYesNo,"Redes") If borrar = vbYes then For n_prueba = 26 To 5 Step -1 num = chr(n_prueba + 64) & ":" On Error Resume Next WshNet.RemoveNetworkDrive num , True Next End if End if perfil = InputBox("Introduzca el perfil al que se desea conectar:", "Unidades de Red - Perfil", "Oficina") Select Case true Case UCase(perfil) = "CASA" Nueva_Unidad "D", "\\192.168.0.1\DATOS", NULL, NULL Case UCase(perfil) = "OFICINA" Nueva_Unidad "D", "\\servidor\Documentos", "administrador", "1234" Nueva_Unidad "S", "\\servidor\Software", "administrador", "1234" Nueva_Unidad "U", "\\servidor\Usuarios", "administrador", "1234" Case UCase(perfil) = "CLIENTE1" Nueva_Unidad "P", "\\220.10.60.8\Excels", "usuario", "contraseña" End Select 'Enumerar las unidades de red EnumerarUnidades 'Liberamos la memoria Set WshNet = Nothing Set WshShell = Nothing Set fso = Nothing Set Unidades_de_red = Nothing WScript.Quit()