none
Adaptar script para registrar login. RRS feed

  • Pergunta

  • Pessoal,

    Utilizo o script abaixo, e tentei adaptá-lo para que no arquivo gerado seja informado o login do usuário também, no momento ele registra apenas o hostname. A modificação que eu fiz não funcionou, podem me auxiliar por favor.

    'Scritp que gera um arquivo texto na unidade c: com o hostname.
    
    'O arquivo gerado informa todas as unidades de rede e impressoras mapeadas.
    
    '=====================================================
    
    option explicit
    
    
    
    Dim objNetwork
    
    Dim colDrives
    
    Dim i
    
    Dim objFSO
    
    Dim objFile
    
    Dim strComputer
    
    Dim objWMIService
    
    Dim objPrinter
    
    Dim colInstalledPrinters
    
    Dim colItems
    
    Dim objItem
    
    Dim strComputador
    
    
    
    <span style="text-decoration: underline;">Dim strUserName
    
    strUserName = lcase(objNetwork.UserName)</span>
    
    
    
    
    
    strComputer = "."
    
    
    
    
    
    Set objNetwork = WScript.CreateObject("WScript.Network")
    
    strComputador = objNetwork.ComputerName
    
    
    
    Const ForWriting = 2
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    Set objFile = objFSO.CreateTextFile("c:\"& strComputador & ".txt", ForWriting)
    
    
    
    
    
    
    
    Set colDrives = objNetwork.EnumNetworkDrives
    
    For i = 0 to colDrives.Count-1 Step 2
    
    objFile.WriteLine colDrives.Item(i) & vbTab & colDrives.Item (i + 1)
    
    objFile.WriteLine " "
    
    objFile.WriteLine "********************************************************************"
    
    objFile.WriteLine " "
    
    Next
    
    
    
    
    
    objFile.Close
    
    
    
    strComputer = "."
    
    Const ForAppending = 8
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    Set objFile = objFSO.OpenTextFile("c:\"& strComputador & ".txt", ForAppending)
    
    
    
    Set objWMIService = GetObject("winmgmts:" _
    
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set colInstalledPrinters = objWMIService.ExecQuery _
    
     ("SELECT * FROM Win32_Printer")
    
    For Each objPrinter in colInstalledPrinters
    
    objFile.WriteLine "Name: " & objPrinter.Name
    
     objFile.WriteLine "Location: " & objPrinter.Location
    
    objFile.WriteLine " "
    
    objFile.WriteLine "********************************************************************"
    
    objFile.Writeline " "
    
    Next
    
    
    
    Set colItems = objWMIService.ExecQuery _
    
        ("Select * from Win32_ComputerSystem")
    
    For Each objItem in colItems
    
        objfile.Writeline "Computer Name: " & objItem.Name
    
        <span style="text-decoration: underline;">objfile.Writeline "User Name: " & objNetwork.UserName</span>
    
    Next
    
    
    
    objFile.Close
    
    
    
    '=========================================================
    
    

    Eu sublinhei os códigos que acrescentei, mas ocorre um erro na linha 23, caract. 1, cuja mensagem é "Objeto Necessário:" E aproveitando, como devo proceder para concatenar o valor de duas variáveis, por exemplo,  c:\"& strComputador & "_"& strUsername & ".txt"

    Grato pela ajuda.
    sexta-feira, 2 de outubro de 2009 13:56

Respostas

  • Olá,

    Verifique abaixo:




    option explicit



    Dim objNetwork

    Dim colDrives

    Dim i

    Dim objFSO

    Dim objFile

    Dim strComputer

    Dim objWMIService

    Dim objPrinter

    Dim colInstalledPrinters

    Dim colItems

    Dim objItem

    Dim strComputador

    Dim strUserName







    strComputer = "."





    Set objNetwork = WScript.CreateObject("WScript.Network")

    strComputador = objNetwork.ComputerName

    strUserName = lcase(objNetwork.UserName)

    Const ForWriting = 2

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFSO.CreateTextFile("c:\"& strComputador & "_" & strUsername & ".txt", ForWriting)







    Set colDrives = objNetwork.EnumNetworkDrives

    For i = 0 to colDrives.Count-1 Step 2

    objFile.WriteLine colDrives.Item(i) & vbTab & colDrives.Item (i + 1)

    objFile.WriteLine " "

    objFile.WriteLine "********************************************************************"

    objFile.WriteLine " "

    Next





    objFile.Close



    strComputer = "."

    Const ForAppending = 8

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFSO.OpenTextFile("c:\"& strComputador & ".txt", ForAppending)



    Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colInstalledPrinters = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_Printer")

    For Each objPrinter in colInstalledPrinters

    objFile.WriteLine "Name: " & objPrinter.Name

     objFile.WriteLine "Location: " & objPrinter.Location

    objFile.WriteLine " "

    objFile.WriteLine "********************************************************************"

    objFile.Writeline " "

    Next



    Set colItems = objWMIService.ExecQuery _
        ("Select * from Win32_ComputerSystem")

    For Each objItem in colItems

        objfile.Writeline "Computer Name: " & objItem.Name

        objfile.Writeline "User Name: " & objNetwork.UserName

    Next



    objFile.Close



    Até mais,

    Jesiel

    Obs.: Se útil, classifique

    • Marcado como Resposta Edson S Freitas sexta-feira, 2 de outubro de 2009 14:32
    sexta-feira, 2 de outubro de 2009 14:12

Todas as Respostas

  • Olá,

    Verifique abaixo:




    option explicit



    Dim objNetwork

    Dim colDrives

    Dim i

    Dim objFSO

    Dim objFile

    Dim strComputer

    Dim objWMIService

    Dim objPrinter

    Dim colInstalledPrinters

    Dim colItems

    Dim objItem

    Dim strComputador

    Dim strUserName







    strComputer = "."





    Set objNetwork = WScript.CreateObject("WScript.Network")

    strComputador = objNetwork.ComputerName

    strUserName = lcase(objNetwork.UserName)

    Const ForWriting = 2

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFSO.CreateTextFile("c:\"& strComputador & "_" & strUsername & ".txt", ForWriting)







    Set colDrives = objNetwork.EnumNetworkDrives

    For i = 0 to colDrives.Count-1 Step 2

    objFile.WriteLine colDrives.Item(i) & vbTab & colDrives.Item (i + 1)

    objFile.WriteLine " "

    objFile.WriteLine "********************************************************************"

    objFile.WriteLine " "

    Next





    objFile.Close



    strComputer = "."

    Const ForAppending = 8

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFSO.OpenTextFile("c:\"& strComputador & ".txt", ForAppending)



    Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colInstalledPrinters = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_Printer")

    For Each objPrinter in colInstalledPrinters

    objFile.WriteLine "Name: " & objPrinter.Name

     objFile.WriteLine "Location: " & objPrinter.Location

    objFile.WriteLine " "

    objFile.WriteLine "********************************************************************"

    objFile.Writeline " "

    Next



    Set colItems = objWMIService.ExecQuery _
        ("Select * from Win32_ComputerSystem")

    For Each objItem in colItems

        objfile.Writeline "Computer Name: " & objItem.Name

        objfile.Writeline "User Name: " & objNetwork.UserName

    Next



    objFile.Close



    Até mais,

    Jesiel

    Obs.: Se útil, classifique

    • Marcado como Resposta Edson S Freitas sexta-feira, 2 de outubro de 2009 14:32
    sexta-feira, 2 de outubro de 2009 14:12
  • Obrigado, funcionou.

    Abraços.
    sexta-feira, 2 de outubro de 2009 14:32