none
Script de Mapeo de Unidades e Impresoras RRS feed

  • Debate general

  • '*********************************************************************************
    ' Inicio del Login Script Global
    '*********************************************************************************
    Option Explicit
    On Error Resume Next
    '*********************************************************************************
    ' Definicion de variables
    '*********************************************************************************
    Dim WSHNetwork, FSO, strUserName, strUserDomain, ObjGroupDict, objDisk, objNetwork, objWMIService, colDisks, WshShell
    '*********************************************************************************
    ' Seto de Variables
    '*********************************************************************************
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    Set FSO = CreateObject("Scripting.FileSystemObject")
    strUserName = ""
    While strUserName = ""
    WScript.Sleep 100 ' 1/10 th of a second
    strUserName = WSHNetwork.UserName
    Wend
    strUserDomain = WSHNetwork.UserDomain
    Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
    Set objNetwork = CreateObject("Wscript.Network")
    Set objWMIService = GetObject("winmgmts:\root\cimv2")
    Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
    Set WshShell = CreateObject("WScript.Shell")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    '********************************************************************************
    'BORRO IMPRESORAS PARA EVITAR ERRORES DE CONEXIONES PREVIAS
    '********************************************************************************
    If MemberOf(ObjGroupDict, "Domain Users") Then
    WSHNetwork.RemovePrinterConnection "\\Servidor.dominio.com\Print-Queue_001

    WSHNetwork.RemovePrinterConnection "\\Servidor.dominio.com\Print-Queue_002

    WSHNetwork.RemovePrinterConnection "\\Servidor.dominio.com\Print-Queue_003

    End If

    '********************************************************************************
    'Copia en Escritorio las Direcciones URLS de Intranet
    '********************************************************************************
    'Borrar antiguo icono de reporte de tiempos
    If MemberOf(ObjGroupDict, "Domain Users") Then
    FSO.DeleteFile "C:\Documents and Settings\All Users\Escritorio\Antiguo*.*", true
    End If
    If MemberOf(ObjGroupDict, "Grupo_determinado") Then
    FSO.CopyFile "\\dominio.com.ar\netlogon\urls\Sis*.*", "C:\Documents and Settings\All Users\Escritorio\", true
    End If
    If MemberOf(ObjGroupDict, "Domain Users") Then
    FSO.CopyFile "\\dominio.com.ar\netlogon\urls\Intranet*.*", "C:\Documents and Settings\All Users\Escritorio\", true
    FSO.CopyFile "\\dominio.com.ar\netlogon\urls\Reporte*.*", "C:\Documents and Settings\All Users\Escritorio\", true
    FSO.CopyFile "\\dominio.com.ar\netlogon\urls\ServidorWeb*.*", "C:\Documents and Settings\All Users\Escritorio\", true
    FSO.CopyFile "\\dominio.com.ar\netlogon\urls\PortalDeServidor*.*", "C:\Documents and Settings\All Users\Escritorio\", true
    End If
    '********************************************************************************
    'Mapeo de Unidades de Red

    '********************************************************************************
    Remove_Old_Drives
    If MemberOf(ObjGroupDict, "Domain Users") Then
    WSHNetwork.MapNetworkDrive "U:" , "\\Servidor\Share"
    WSHNetwork.MapNetworkDrive "P:" , "\\Servidor\Share_2\" _
    & WSHNetwork.UserName

    If strUserName = "user_xxx" Then
    WshShell.Run "\\dominio.COM.AR\NETLOGON\script.bat"
    end if

    If MemberOf(ObjGroupDict, "Grupo - Determinado") Then
    WshShell.Run "\\dominio.COM.AR\NETLOGON\MAP_X.bat"
    End If


    '********************************************************************************
    'Mapeo de Impresoras
    '********************************************************************************

    If MemberOf(ObjGroupDict, "Print-Queue-001") Then
    WSHNetwork.AddWindowsPrinterConnection "\\Servidor.dominio.com.ar\Print-Queue-001"
    End If
    If MemberOf(ObjGroupDict, "Print-Queue-002") Then
    WSHNetwork.AddWindowsPrinterConnection \\Servidor.dominio.com.ar\Print-Queue-002
    End If
    If MemberOf(ObjGroupDict, "Print-Queue-003") Then
    WSHNetwork.AddWindowsPrinterConnection "\\Servidor.dominio.com.ar\Print-Queue-003"
    End If

    '********************************************************************************
    'Seteos Especiales por Default para impresoras
    '********************************************************************************

    If MemberOf(ObjGroupDict, "Grupo_Print-Queue-Black&White") Then
    WshNetwork.SetDefaultPrinter "\\Servidor.dominio.com.ar\Print-Queue-Black"
    End If
    If strUserName = "Usuario_xxx" Then
    WshNetwork.SetDefaultPrinter \\Servidor.dominio.com.ar\Print-Queue-Black
    End If

    '********************************************************************************
    'Funciones
    '********************************************************************************
    Function MemberOf(ObjDict, strKey)
    MemberOf = CBool(ObjGroupDict.Exists(strKey))
    End Function

    Function CreateMemberOfObject(strDomain, strUserName)
    Dim objUser, objGroup
    Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
    CreateMemberOfObject.CompareMode = vbTextCompare
    Set objUser = GetObject("WinNT://" _
    & strDomain & "/" _
    & strUserName & ",user")
    For Each objGroup In objUser.Groups
    CreateMemberOfObject.Add objGroup.Name, "-"
    Next
    Set objUser = Nothing
    End Function
    '********************************************************************************
    'Sub-Rutina Elimino Unidades de Red
    '********************************************************************************
    Sub Remove_Old_Drives()
    For each objDisk in colDisks
    If objDisk.DriveType = 4 And objDisk.Name > "F:" Then
    objNetwork.RemoveNetworkDrive objDisk.Name, True, True
    End If
    Next
    End Sub


    Gaston A. Gimené - MCP(MCTS) MCTS: Microsoft Certified Technology Specialist

    jueves, 10 de enero de 2013 14:47