none
Script de mapeamento de impressora e mapeamento de unidades RRS feed

  • Pergunta

  •  

    Galera eu estou usando um script para o seguinte usuario.

     

     

    Set WshNetwork = CreateObject("WScript.Network")

     WshNetwork.AddWindowsPrinterConnection "\\Auto_peça_le\HP810"
     'WshNetwork.SetDefaultPrinter "\\Auto_peça_le\HP810" colocar a impressora como DefaultPrinter Padrão

     WshNetwork.addwindowsPrinterConnection "\\Brunovieira\HP1350"
     
    msgbox "A impressoras foram adicionadas com sucesso"

     

    só que toda vez que o usuario faz o logon ele add a impressora e da a mensagem, eu gostaria de adicionar no script o seguinte, se as impressoras já estiverem instaladas não fazer nada.

     

    e a mesma coisa para o mapeamento de rede, verificar se o usuario já tem o mapeamento.

     

    'Declarar Variáveis
    '---------------------------------------------------------------------------------------
    Option Explicit
    Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3, WshShell, Rafael, CheckDrive
    Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, DriveLetter, RemotePath, AlreadyConnected, i

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set Rafael = WScript.CreateObject("WScript.Network")
    Set CheckDrive = Rafael.EnumNetworkDrives() 

     

    'Verificar permissão e Mapear Unidade G:
    '---------------------------------------------------------------------------------------

    strDriveLetter1 = "G:"
    RemotePath = "\\kelsen\teste1"

    AlreadyConnected = False
    'Rafael.RemoveNetworkDrive strDriveLetter1
    For i = 0 To CheckDrive.Count - 1 Step 2
    If CheckDrive.Item(i) = strDriveLetter1 Then AlreadyConnected = True
    Next

    If AlreadyConnected = True then
    Rafael.RemoveNetworkDrive strDriveLetter1
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    Else
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    End if 

     

    Valew galera espero que me ajudem nessa

    sexta-feira, 23 de novembro de 2007 20:06

Todas as Respostas

  •  

    Você pode tirar do script abaixo as informações que precisa para alterar o seu script com as impressoras,depois é só brincar com o IF.

    No caso do mapeamento de rede usa esses:

     

    strDriveExist = objFSO.DriveExists("w:")
    If strDriveExist = True Then
       objNetwork.RemoveNetworkDrive "w:"
    End If  

     

    Te aconselho a sempre remover o mapeamento pois alguém pode indiscriminadamente usar a mesma unidade emapear outra pasta.

     

    sucesso,

    Romeu

     

     

     

     

    ' PrinterWMI.vbs
    ' Sample VBScript to interrogate Printer properties with WMI
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.3 - December 2005
    ' --------------------------------------------------------------'
    Option Explicit
    Dim objWMIService, objItem, colItems, strComputer, intPrinters

    strComputer ="."
    intPrinters = 1

    ' --------------------------------------------
    ' Pure WMI Section
    Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Printer")

    Call Wait() ' Goto Sub Routine at the end

    ' On Error Resume Next
    For Each objItem In colItems
    WScript.Echo "Printers on " _
    & objItem.name & ", Printer Number: " & intPrinters & VbCr & _
    "====================================" & VbCr & _
    "Availability: " & objItem.Availability & VbCr & _
    "Description: " & objItem.Description & VbCr & _
    "Printer: " & objItem.DeviceID & VbCr & _
    "Driver Name: " & objItem.DriverName & VbCr & _
    "Port Name: " & objItem.PortName & VbCr & _
    "Printer State: " & objItem.PrinterState & VbCr & _
    "Printer Status: " & objItem.PrinterStatus & VbCr & _
    "PrintJobDataType: " & objItem.PrintJobDataType & VbCr & _
    "Print Processor: " & objItem.PrintProcessor & VbCr & _
    "Spool Enabled: " & objItem.SpoolEnabled & VbCr & _
    "Separator File: " & objItem.SeparatorFile & VbCr & _
    "Queued: " & objItem.Queued & VbCr & _
    "Status: " & objItem.Status & VbCr & _
    "StatusInfo: " & objItem.StatusInfo & VbCr & _
    "Published: " & objItem.Published & VbCr & _
    "Shared: " & objItem.Shared & VbCr & _
    "ShareName: " & objItem.ShareName & VbCr & _
    "Direct: " & objItem.Direct & VbCr & _
    "Location: " & objItem.Location & VbCr & _
    "Priority: " & objItem.Priority & VbCr & _
    "Work Offline: " & objItem.WorkOffline & VbCr & _
    "Horizontal Res: " & objItem.HorizontalResolution & VbCr & _
    "Vertical Res: " & objItem.VerticalResolution & VbCr & _
    ""
    intPrinters = intPrinters + 1
    Next

    sub Wait()
    If strComputer = "." then
    strComputer = "Local Host"
    else strComputer = strComputer
    end if

    WScript.Echo "Wait 2 mins for " & strComputer _
    & " to enumerate printers"

    End Sub

    WScript.Quit

    ' End of Sample Printer VBScript
    domingo, 25 de novembro de 2007 00:06
  •  

    Cara eu estou tentdo um erro na hora de roda o script que é o seguinte

     

    Script: c:\Documents and Settings\Teste\Desktop\Script Bruno.vbs

    Linha: 14

    Caract.:1

    Erro: Objeto necessário: 'objFSO'

    Código 800A01A8

    Origem: Erro de tempo de execução do Microsoft VBscript

     

     

    o script abaixo

     

    ' ###Script de mapeamento de Impressora CARLOS###

     

    Set WshNetwork = CreateObject("WScript.Network")

     WshNetwork.AddWindowsPrinterConnection "\\Auto_peça_le\HP810"
      
    '---------------------------------------------------------------------------------------

    ' ###Ver. e Rem. de Mapeamentos###


    strDriveExist = objFSO.DriveExists("y:")

    If strDriveExist = True Then
       objNetwork.RemoveNetworkDrive "y:"

    End If  

    strDriveExist = objFSO.DriveExists("z:")

    If strDriveExist = True Then
       objNetwork.RemoveNetworkDrive "z:"

    End If
    strDriveExist = objFSO.DriveExists("x:")

    If strDriveExist = True Then
       objNetwork.RemoveNetworkDrive "x:"

    End If

    '-------------------------------------------------------------------------------------------------
    ' ###Declaração de Variaveis###

     

    Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3, WshShell, Rafael, CheckDrive
    Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, DriveLetter, RemotePath, AlreadyConnected, i

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set Rafael = WScript.CreateObject("WScript.Network")
    Set CheckDrive = Rafael.EnumNetworkDrives()

     


    ' ###Verificar permissão e Mapear Unidade G[:#]##

     

    strDriveLetter1 = "y:"
    RemotePath = "\\Fenix\Bruno"

    AlreadyConnected = False
    'Rafael.RemoveNetworkDrive strDriveLetter1
    For i = 0 To CheckDrive.Count - 1 Step 2
    If CheckDrive.Item(i) = strDriveLetter1 Then AlreadyConnected = True
    Next

    If AlreadyConnected = True then
    Rafael.RemoveNetworkDrive strDriveLetter1
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    Else
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    End if

    strDriveLetter1 = "z:"
    RemotePath = "\\Fenix\Paraná"

    AlreadyConnected = False
    'Rafael.RemoveNetworkDrive strDriveLetter1
    For i = 0 To CheckDrive.Count - 1 Step 2
    If CheckDrive.Item(i) = strDriveLetter1 Then AlreadyConnected = True
    Next

    If AlreadyConnected = True then
    Rafael.RemoveNetworkDrive strDriveLetter1
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    Else
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    End if

    strDriveLetter1 = "x:"
    RemotePath = "\\Fenix\Protheus8"

    AlreadyConnected = False
    'Rafael.RemoveNetworkDrive strDriveLetter1
    For i = 0 To CheckDrive.Count - 1 Step 2
    If CheckDrive.Item(i) = strDriveLetter1 Then AlreadyConnected = True
    Next

    If AlreadyConnected = True then
    Rafael.RemoveNetworkDrive strDriveLetter1
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    Else
    Rafael.MapNetworkDrive strDriveLetter1, RemotePath

    End if

     

    Valew

    segunda-feira, 26 de novembro de 2007 13:49